<asp:TemplateField HeaderText="Team Leader">
<ItemTemplate>
<asp:Label ID="gvuser_teamleader" runat="server" Text='<%# Bind("TeamLeaderID") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtuserteamleader" runat="server" Width="100px" Text='<%# Eval("TeamLeaderID") %>' CssClass="textboxstyle roundedcorner aligncenter gradientskyblue"></asp:TextBox>
<asp:ListBox ID="listboxuserteamleader" runat="server" Width="110px" AutoPostBack="true" OnSelectedIndexChanged="listboxuserteamleader_SelectedIndexChanged" CssClass="textboxstyle roundedcorner aligncenter gradientskyblue"></asp:ListBox>
<asp:DropDownExtender ID="DropDownExtender3" runat="server" TargetControlID="txtuserteamleader" DropDownControlID="listboxuserteamleader"></asp:DropDownExtender>
</EditItemTemplate>
</asp:TemplateField>
当我尝试触发选定的列表框索引更改事件并尝试将列表框选定值绑定到文本框时,出现此错误。此外,这两个控件都在 gridview 编辑项模板字段内。
我的代码:
protected void listboxuserteamleader_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridViewRow gvr in gvusers.Rows)
{
TextBox txtuserteamleader = (TextBox)gvusers.FindControl("txtuserteamleader");
ListBox listboxuserteamleader = (ListBox)gvusers.FindControl("listboxuserteamleader");
txtuserteamleader.Text = listboxuserteamleader.SelectedValue.ToString();
}
}