我有在GridView里面像下拉列表中删除项目,从下拉列表永久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一次,它应该被删除从网格的选定行下拉列表中选择。它不会再显示。
上述代码正在工作。但是,如果我刷新页面,它正在显示
如何解决此问题?
是否需要在任何其他事件中创建项目?
如果我删除网格的第二行(页面索引1)中的LOP。它会影响网格所有页面的所有第二行。 – user7415073
然后,您需要在会话中使用第三个条件,即GridView的页面或标识。用你自己的包含3个属性的类代替'KeyValuePair'。 – VDWWD
你非常感谢你的回答 – user7415073