问题下拉事件onselectedIndexChange [英] problem dropdown event onselectedIndexChange
本文介绍了问题下拉事件onselectedIndexChange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
我的.aspx页在下面给出..
Dear all,
my .aspx page given below..
<table class="style1">
<tr>
<td>
<asp:DropDownList ID="Ddl" runat="server"
onselectedindexchanged="Ddl_SelectedIndexChanged">
<asp:ListItem Value=0 Selected="True">------Select-----</asp:ListItem>
<asp:ListItem Value=1>National Sales Manager</asp:ListItem>
<asp:ListItem Value=2>Regional Manager</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" Height="66px" Width="689px">
</asp:CheckBoxList>
</td>
<td>
</td>
</tr>
</table>
----和我的aspx.cs页面---
----and my aspx.cs page ---
public partial class Test : System.Web.UI.Page
{
SqlConnection ConnDeemah = new SqlConnection();
public string Cmd = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// BindCheckboxList();
}
}
public void BindCheckboxList()
{
string connectionString = (string)ConfigurationSettings.AppSettings["ConnectionString"];
ConnDeemah.ConnectionString = connectionString;
ConnDeemah.Open();
SqlDataReader nsmDr;
Cmd = "SELECT Convert(varchar, NSM.NationalSalesManagerCode)+ '' - '' + NSM.NationalSalesManagerName + '' / '' + C.CountryName As NationalSalesManagerName, NSM.NationalSalesManagerCode FROM NationalSalesManager NSM INNER JOIN Country C ON NSM.NationalSalesManagerCode = C.NationalSalesManagerCode ORDER BY NationalSalesManagerName";
SqlCommand RCMD = new SqlCommand(Cmd, ConnDeemah);
nsmDr = RCMD.ExecuteReader(CommandBehavior.CloseConnection);
CheckBoxList1.DataSource = nsmDr;
CheckBoxList1.DataTextField = "NationalSalesManagerName";
CheckBoxList1.DataValueField = "NationalSalesManagerCode";
CheckBoxList1.DataBind();
}
protected void Ddl_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Ddl.SelectedValue == "1")
{
CheckBoxList1.Visible = true;
BindCheckboxList();
}
else if (Ddl.SelectedValue == "2")
{
CheckBoxList1.Visible = true;
BindCheckboxList();
}
}
上面的代码正常工作,但是我不想在按钮单击事件上填写复选框列表,当我将按钮事件代码放在Ddl_SelectedIndexChanged事件的块中时,它确实会填充复选框列表.
因此,请有人帮助我.................
the above code is working properly ,but I don''t want to fill the checkboxlist on button click event,when I put button event code in the block of Ddl_SelectedIndexChanged event then it does populate the checkboxlist.
so please somebody help me.................
推荐答案
将dropdownlist的AutoPostBack属性设置为TRUE.
Set AutoPostBack property of dropdownlist to TRUE.
<asp:DropDownList ID="Ddl" runat="server" AutoPostBack="true"
onselectedindexchanged="Ddl_SelectedIndexChanged">
<asp:ListItem Value=0 Selected="True">------Select-----</asp:ListItem>
<asp:ListItem Value=1>National Sales Manager</asp:ListItem>
<asp:ListItem Value=2>Regional Manager</asp:ListItem>
</asp:DropDownList>
这篇关于问题下拉事件onselectedIndexChange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文