I have a page which have many dropdown..If a user changes the values of 'n' number of dropdown ,and then he clicks save button..a dialog box should appear which should give the message that 'n' no. of dropdown has been changed..
My drop-down list is this-
<asp:DropDownList id="dd" runat="server" Width="87px" Font-Size="XX-Small" >
<asp:ListItem Value="Pending">Pendingasp:ListItem>
<asp:ListItem Value="Yes">Yesasp:ListItem>
<asp:ListItem Value="No">Noasp:ListItem>
asp:DropDownList>
Save button is this-
<asp:imagebutton id="btnSaveChanges" runat="server" ImageUrl="images/save.gif" ImageAlign="Bottom" >asp:imagebutton>
<asp:Label id="SaveData" runat="server" >Save Changesasp:Label>
Loading
Nilanka DharmadasaPosted Jan 7, 2010, 2:22 AM
This code can be used for amy number of dropdowns. I havent hardcoded the number of dropdowns in the code.
Use it.
private int numberofchangeddropdown = 0;
private System.Collections.ArrayList dropdowns = new System.Collections.ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
foreach (Control c in this.Controls)
{
if (c is DropDownList)
{
DropDownList obj = (DropDownList)c;
obj.SelectedIndexChanged += new System.EventHandler(this.Dropdownlist_SelectedIndexChanged);
//You bind the same event to all the dropdowns.
}
}
}
protected void Dropdownlist_SelectedIndexChanged(object sender, EventArgs e)
{
//You check whether you already counted that dropdown. Otherwise if you change one dropdown two times it will count 2 which is not correct.
if (!dropdowns.Contains(sender))
{
dropdowns.Add(sender);
numberofchangeddropdown++;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Page.RegisterClientScriptBlock("msg", "");
}
If this answer helps you, please tick "do you like this answer' checkbox.
Santhosh NPosted Jan 7, 2010, 1:29 AM
static int cnt = 0;
protected void Page_Load(object sender, EventArgs e)
{
Dropdownlist1.Items.Add("1");
Dropdownlist1.Items.Add("2");
Dropdownlist2.Items.Add("one");
Dropdownlist2.Items.Add("two");
Dropdownlist3.Items.Add("1one");
Dropdownlist3.Items.Add("2two");
}
protected void Dropdownlist1_SelectedIndexChanged(object sender, EventArgs e)
{
//cnt += 1;
}
protected void Dropdownlist2_SelectedIndexChanged(object sender, EventArgs e)
{
//cnt += 1;
}
protected void Dropdownlist3_SelectedIndexChanged(object sender, EventArgs e)
{
//cnt += 1;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Dropdownlist1.SelectedIndex != 0)
cnt += 1;
if (Dropdownlist2.SelectedIndex != 0)
cnt += 1;
if (Dropdownlist3.SelectedIndex != 0)
cnt += 1;
Page.RegisterClientScriptBlock("msg", "");
cnt = 0;
}