如何在c#中使用updatepanel清除Dropdownlist? [英] How to clear Dropdownlist with updatepanel in c#?
本文介绍了如何在c#中使用updatepanel清除Dropdownlist?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有drodownlist,复选框中有自动回发的复选框。
Ex
Hi,
I have drodownlist,checkbox with auto postback in Update panel.
Ex
<asp:updatePanel id="UPD1" runat="Server" UpdateMode="Conditional">
<asp:checkbox id="chk1" runat="server" autopostback="True" OnCheckedChanged="chkAllView_CheckedChanged" />
<asp:dropdownList id="ddl1" runat="server"/>
Protected void Page_Load()
{
if(!IsPostBack)
{
DataSet Objds1 = ;
ddl1.dataSource =Objds1;
ddl1.databind();
}
}
Protected void chk1_CheckedCObject o,sender e)
{
If(Chk1.Checked){
ddl.Items.Clear();}
}
下拉列表项目是我点击Checkbox时不清楚。
请让我知道解决方案。
Dropdownlist items is not clear when I click Checkbox.
Please let me know the for Solutions.
推荐答案
这是我用过的,它为我工作.....
This is how i have used, its working for me.....
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:CheckBox ID="chk1" runat="server" AutoPostBack="True" OnCheckedChanged="chkAllView_CheckedChanged" />
<asp:DropDownList ID="ddl1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</div><pre lang="cs">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<string> lst = new List<string>();
lst.Add("praveen");
lst.Add("nanda");
lst.Add("pradeep");
ddl1.DataSource = lst;
ddl1.DataBind();
}
}
protected void chkAllView_CheckedChanged(object sender, EventArgs e)
{
if (chk1.Checked)
{
ddl1.Items.Clear();
}
}</pre>
<asp:DropDownList ID="DropDownList1" Width="150" runat="server" AutoPostBack="true">
</asp:DropDownList>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:updatePanel id="UPD1" runat="Server" UpdateMode="Conditional">
<ContentTemplate>
<br />
<asp:CheckBox ID="chk1" runat="server" AutoPostBack="true" OnCheckedChanged="chkAllView_CheckedChanged" />
<asp:DropDownList ID="ddl1" runat="server">
</asp:DropDownList>
</ContentTemplate>
</asp:updatePanel>
</div>
</form>
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
DataSet ds ; //set dataset values here
ddl1.DataSource=ds;
ddl1.DataBind();
}
}
protected void chkAllView_CheckedChanged(object sender, EventArgs e)
{
if(chk1.Checked)
ddl1.Items.Clear();
}
修改如上。
Modify as above.
这篇关于如何在c#中使用updatepanel清除Dropdownlist?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文