[英]ASP.NET DropDownList inside ListView
Hey guys i need your helps.. Why i cant refer for my veriable to the DropDownList control in the code-behind? 大家好,我需要您的帮助。为什么我无法在代码后面引用我的Veriable到DropDownList控件? I would add that the control is in the control of another in a ListView but when the DropDownList control will be is out of the ListView I can refer to it. 我要补充一点,该控件在ListView中的另一个控件中,但是当DropDownList控件将不在ListView中时,我可以引用它。 Where is the Devil??. 魔鬼在哪里? Regards 问候
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="view.aspx.cs" Inherits="Sites_view" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="center" Runat="Server">
<form id="formluarz" method="post" action="">
<div id="form-view">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:practiceConnectionString %>"
SelectCommand="SELECT k.idKlienci, k.imie, k.nazwisko, k.adres, k.miasto, r.idRezerwacje, r.data, r.godzina, r.idKlienci FROM klienci AS k INNER JOIN rezerwacje AS r ON k.idKlienci = r.idKlienci"
UpdateCommand="UPDATE Klienci SET imie = @imie, nazwisko = @nazwisko, adres = @adres, miasto = @miasto WHERE (idKlienci = @IdKlienci)UPDATE rezerwacje SET data = @data, godzina = @godzina WHERE (idRezerwacje = @idRezerwacje)"
></asp:SqlDataSource>
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="idRezerwacje, idKlienci" ConvertEmptyStringToNull="true" >
<LayoutTemplate>
<asp:DataPager ID="DataPager1" runat="server" PageSize="10" >
<Fields>
<asp:NextPreviousPagerField ButtonType="Link" ButtonCssClass="pagin" ShowFirstPageButton="true"/>
<asp:NumericPagerField NumericButtonCssClass="pagin" CurrentPageLabelCssClass="pagin"/>
</Fields>
</asp:DataPager>
<table cellpadding="2" runat="server" id="tblDepartments" width="640px" cellspacing="1">
<tr id="Tr1" runat="server" class="TableHeader">
<td id="Td1" runat="server">Edycja</td>
<td id="Td2" runat="server">imie</td>
<td id="Td3" runat="server">nazwisko</td>
<td id="Td7" runat="server">adres</td>
<td id="Td8" runat="server">miasto</td>
<td id="Td5" runat="server">data</td>
<td id="Td6" runat="server">godzina</td>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<EditItemTemplate>
<tr >
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td >
<asp:Label runat="server" ID="NameLabel" AssociatedControlID="NameTextBox"
Text="Imie" Font-Bold="true"/><br />
<asp:TextBox ID="NameTextBox" runat="server" Text='<%#Bind("imie") %>' />
</td>
<td >
<asp:Label runat="server" ID="GroupNameLabel" AssociatedControlID="SurnameTextBox"
Text="Nazwisko" Font-Bold="true" /><br />
<asp:TextBox ID="SurnameTextBox" runat="server" Width="150px" Text='<%#Bind("nazwisko") %>' />
<br />
</td>
<td >
<asp:Label runat="server" ID="Label1" AssociatedControlID="AdressTextBox"
Text="Adres" Font-Bold="true" /><br />
<asp:TextBox ID="AdressTextBox" runat="server" Width="150px" Text='<%#Bind("adres") %>' />
<br />
</td>
<td >
<asp:Label runat="server" ID="Label2" AssociatedControlID="CityTextBox"
Text="Miasto" Font-Bold="true" /><br />
<asp:TextBox ID="CityTextBox" runat="server" Width="150px" Text='<%#Bind("miasto") %>' />
<br />
</td>
<td class="EditItem">
<asp:Label runat="server" ID="Label3" AssociatedControlID="DateTextBox"
Text="Data" Font-Bold="true" /><br />
<div id="ab">
<div id="a"><asp:TextBox ID="DateTextBox" runat="server" ClientIDMode="Static" Width="100px" Text='<%#Bind("data") %>' /></div><div id="b"><asp:image ID="Image1" runat="server" CssClass="image" style="cursor:hand;" onclick="PopupDatePicker('DateTextBox')" ImageUrl="~/image/ikon.png" /></div></div>
</td>
<td >
<asp:Label runat="server" ID="Label4"
Text="Godzina" Font-Bold="true" /><br />
<asp:DropDownList ID="DropDownList1" runat="server" >
</asp:DropDownList>
</td>
</tr>
</EditItemTemplate>
<ItemTemplate>
<tr runat="server">
<td>
<asp:Button ID="EditButton" runat="server" Text="Edit" CommandName="Edit" />
</td>
<td>
<asp:Label ID="NameLabel" runat="server" Text='<%#Eval("imie") %>' />
</td>
<td>
<asp:Label ID="SurnameLabel" runat="server" Text='<%#Eval("nazwisko") %>' />
</td>
<td>
<asp:Label ID="AdressLabel" runat="server" Text='<%#Eval("adres") %>' />
</td>
<td>
<asp:Label ID="CityLabel" runat="server" Text='<%#Eval("miasto") %>' />
</td>
<td>
<asp:Label ID="DataLabel" runat="server" Text='<%#Eval("data") %>' />
</td>
<td>
<asp:Label ID="TimeLabel" runat="server" Text='<%#Eval("godzina") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</div>
</form>
</asp:Content>
aspx.cs aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
string ktr, mtr;
for (int k = 0; k < 24; k++)
{
for (int m = 0; m < 60; m = m + 5)
{
if (k < 10)
{
ktr = "0" + k.ToString();
}
else
{
ktr = k.ToString();
}
if (m < 10)
{
mtr = "0" + m.ToString();
}
else
{
mtr = m.ToString();
}
DropDownList1.Items.Add(new ListItem(ktr + ":" + mtr)); //cant refer :(
}
}
}
First of all, I suggest you to check if you really trigger that Page_Load event with a simple break point. 首先,我建议您检查是否真的通过简单的断点触发了Page_Load事件。 Secondly I highly recommend you override The "OnLoad" event instead of "Page_Load". 其次,我强烈建议您重写“ OnLoad”事件而不是“ Page_Load”事件。
You would have something like this in the .aspx.cs: 您将在.aspx.cs中得到以下内容:
protected override void OnLoad(EventArgs e)
{
string ktr, mtr;
for (int k = 0; k < 24; k++)
{
for (int m = 0; m < 60; m = m + 5)
{
if (k < 10)
{
ktr = "0" + k.ToString();
}
else
{
ktr = k.ToString();
}
if (m < 10)
{
mtr = "0" + m.ToString();
}
else
{
mtr = m.ToString();
}
DropDownList1.Items.Add(new ListItem(ktr + ":" + mtr));
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.