1
Answer

total count of dropdown's selected

Kriti

Kriti

14y
3.4k
1

My dropdown code is
<
asp:DropDownList id="dd" runat="server" Width="87px" Font-Size="XX-Small" OnSelectedIndexChanged="dd_SelectedIndexChanged" AutoPostBack="true" >
<asp:ListItem Value="Item1">Item1</asp:ListItem>
<asp:ListItem Value="Item2">Item2</asp:ListItem>
<asp:ListItem Value="Item3">Item3</asp:ListItem>
</asp:DropDownList>
<
input type="hidden" id="inpHide" runat="server" value="0" />
<input type="hidden" id="hidSendNotification" runat="server" value="0" />
Java Script Code
<
script type="text/javascript">
function
ConfirmItTest(inpHide) {
var getValue=parseInt(document.getElementById(inpHide).value);
if (getValue>0)
{
if(confirm("Do you want to send notifications to "+document.getElementById(inpHide).value +"  Owners."))
{
document.getElementById(
"<%=hidSendNotification.ClientID%>").value="1";
return true;
}
else{false;}
}
else
{
alert(
"NO CHANGES DONE");
return false;
}
}
</script>
MY Page retrieves many dropdown.Supposing i have selected items of 3 dropdown then a dialog box appears saying that "Do you want to send notification to 3 owners".
Dropdown code in codebehind is'
protected
void dd_SelectedIndexChanged(object sender, EventArgs e)
{
int count = 0;
count =
Convert.ToInt32(inpHide.Value);
for (int i = 0; i < m_grid.Items.Count; i++)
{
if (((DropDownList)sender).ClientID == m_grid.Items[i].FindControl(((DropDownList)sender).ID).ClientID)
{
if (((DropDownList)sender).SelectedValue != m_grid.Items[i].Cells[1].Text)
{
count++;
}
}
}
inpHide.Value = count.ToString();
}
Problem is that..
Supposing if i select dopdown1-> item1 but again i change my decision and select item2 of same dropdown1.BUT the count appears as 2 since i have cilkes twice on same dropdown and hence dialog box says "Do you want to send notification to 2 owners".Count should be 1 since I have selected only 1 dropdown.
How to handle correct count in this scenario?

Answers (1)