【发布时间】:2017-03-07 16:35:08
【问题描述】:
我在 Gridview 中有下拉列表,例如,
<asp:TemplateField HeaderText="Leave Category" >
<ItemTemplate>
<asp:DropDownList ID="LCList" runat ="server" AutoPostBack="true" OnSelectedIndexChanged="LCList_TextChanged"/>
</ItemTemplate>
</asp:TemplateField>
并添加类似的项目,
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList LCList = (e.Row.FindControl("LCList") as DropDownList);
LCList.Items.Insert(0, new ListItem("casual Leave"));
LCList.Items.Insert(1, new ListItem("sick Leave"));
LCList.Items.Insert(2, new ListItem("LOP"));
}
}
如果我选择 LOP 一次,它应该从网格的选定行下拉列表中删除。不会再显示了。
上面的代码正在运行。但是如果我刷新页面,它正在显示
如何解决?
是否需要在任何其他事件中创建项目?
【问题讨论】: