У меня есть DropDownList
в шаблоне редактирования, связанном с некоторыми данными. Хотя у меня также есть Label
в шаблоне элемента, привязанного к представленным данным. Теперь я не могу получить Label
всякий раз, когда я вызвал метод ниже. Счетчик всегда нулевой / пустой. Кто-нибудь может мне помочь?
Код:
protected void ManageStaffGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (ManageStaffGrid.EditIndex == e.Row.RowIndex && e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < ManageStaffGrid.Rows.Count; i++)
{
#region get selected items bound
Label sectionname = ((Label)ManageStaffGrid.Rows[i].Cells[2].FindControl("lblSection"));
Label functionname = ((Label)ManageStaffGrid.Rows[i].Cells[3].FindControl("lblFunction"));
Label rolename = ((Label)ManageStaffGrid.Rows[i].Cells[5].FindControl("lblRole"));
#endregion
ListBox ListSection = (ListBox)e.Row.Cells[2].FindControl("ListSection");
ListSection.DataSource = dbmanager.GetAllSection();
ListSection.DataBind();
DropDownList ddlFunction = (DropDownList)e.Row.Cells[3].FindControl("ddlFunction");
ddlFunction.DataSource = dbmanager.GetAllFunction();
ddlFunction.DataBind();
ddlFunction.SelectedValue = functionname.ToString();
DropDownList ddlRole = (DropDownList)e.Row.Cells[5].FindControl("ddlRole");
ddlRole.DataSource = dbmanager.GetAllRole();
ddlRole.DataBind();
ddlRole.SelectedValue = rolename.ToString();
}
}
}
Конструкция:
<asp:GridView ID="ManageStaffGrid" runat="server" BorderStyle="Solid"
BorderWidth="1px" onrowediting="ManageStaffGrid_RowEditing"
onrowdatabound="ManageStaffGrid_RowDataBound" AutoGenerateColumns="False"
onrowcancelingedit="ManageStaffGrid_RowCancelingEdit"
onrowupdating="ManageStaffGrid_RowUpdating">
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True"/>
<asp:BoundField DataField="Uid" HeaderText="User ID" ReadOnly="True"/>
<asp:TemplateField HeaderText="Section">
<EditItemTemplate>
<asp:ListBox ID="ListSection" SelectionMode="Multiple" runat="server"
onMouseDown="GetCurrentListValues(this);" onchange="FillListValues(this);"
Height="20px" Width="80px"></asp:ListBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblSection" runat="server" Text='<%# Bind("Section") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Function">
<EditItemTemplate>
<asp:DropDownList ID="ddlFunction" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblFunction" runat="server" Text='<%# Bind("Function") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Sex" HeaderText="Sex" ReadOnly="True"/>
<asp:TemplateField HeaderText="Role">
<EditItemTemplate>
<asp:DropDownList ID="ddlRole" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblDropdown" runat="server" Text='<%# Bind("Role") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True">
<ControlStyle Font-Size="Medium" />
</asp:CommandField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="DeleteBtn" runat="server"
OnClientClick="return confirm('Are you sure you want to delete this question?');"
onclick="DeleteBtn_Click">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>