On each button click, on selection of the dropdownlist item, get the count of selected listitem and put it in a textbox.
Output:
Rajesh: 2(selected 2 times on button click)
Vinay : 5(selected 5 times)
On each button click, on selection of the dropdownlist item, get the count of selected listitem and put it in a textbox.
Output:
Rajesh: 2(selected 2 times on button click)
Vinay : 5(selected 5 times)
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
ramya bharathPosted Jun 3, 2015, 10:45 PM
I.e on page load create the dictionary
On selection change if rajesh is selected add key as Rajesh vand value as 1.
On selection of vinay add similarly in the dictionary.
d developerPosted Jun 3, 2015, 1:32 PM
Nanhe SiddiquePosted May 30, 2015, 12:57 AM
Pankaj Kumar ChoudharyPosted May 29, 2015, 7:36 PM
protected void Page_Load(object sender, EventArgs e)
{
// Load_Data();
if (!IsPostBack)
{
Dictionary.Add("Rajesh", 0);
Dictionary.Add("Vinay", 0);
Dictionary.Add("Hari", 0);
Dictionary.Add("Anand", 0);
}
}
{
if (DropDownList1.SelectedValue == "Rajesh")
Dictionary["Rajesh"] = Dictionary["Rajesh"] + 1;
else if (DropDownList1.SelectedValue == "Vinay")
Dictionary["Vinay"] = Dictionary["Vinay"] + 1;
else if (DropDownList1.SelectedValue == "Hari")
Dictionary["Hari"] = Dictionary["Hari"] + 1;
else if (DropDownList1.SelectedValue == "Anand")
Dictionary["Anand"] = Dictionary["Anand"] + 1;
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (KeyValuePair
{
Response.Write(inr.Key + "= " + inr.Value);
}
Dictionary["Rajesh"] = 0; // here reset the each dictionary value //
Dictionary["Vinay"] = 0; // you can avoid this code if you don't require //
Dictionary["Hari"] = 0;
Dictionary["Anand"] = 0;
}
}
ramya bharathPosted May 29, 2015, 3:55 PM
On each select you have to check which value has been selected and on button click display the count of total selection.
Steps to be followed.
1. Create a public hash table in your code. Either in server side or client side anything is fine
Am providing an example in JavaScript since c# you can create dictionary objects which is easier
Code 1
var myArray = {Rajesh:0,Vinay:0}:
2. On selection change create a event to check what selection it is and update the value of it
Code 2:
myArray[selectedvalue] = myArray[selectedvalue]+1;
3. On button click call a event to loop through all the elements of the array and append the value in text box
for(key in myArray) {
Displaytextbox.text=Displaytextbox.text+key+":"+myArray[key];
}
Refer this on how to handle associated array in JavaScript http://blog.xkoder.com/2008/07/10/javascript-associative-arrays-demystified/
Refer this on how to do it using dictionary in server side http://www.dotnetperls.com/dictionary