Saturday, 30 March 2013

To get the values from ArrayList

I write the code for to add multiple radio buttons dynamically in table.. each cell have 4-5 radio buttons and each row have several radio buttons with different group name.. each radio button id i can add in arraylist. my problem how to get the checked radio buttons ids in arraylist


Ans
         If you finally want to get the id's of the selected radio-buttons in the ArrayList at server.I think you can do this with little javascript.

Say, you have a table with lots of radio buttons. And a submit button for submitting the form.

Follow these steps:

1)Make a javascript function which collects the ids of selected radio buttons and add them up in a string separated by unique character, and name it COLLECTOR FUNCTION. Say, the user selects cricket, tennis and basket ball radio buttons then the function should return "c#t#b" where # is the unique character and c,t,b are their respective ids.

2)When the user clicks on the submit button, in its event handler function call collector function
and make an ajax get request to the server with the output of collector function as query string.
eg. make request "arrylist.aspx?q=c#t#b"

3)Get that query string at server side, and split the ids through string's split function
and store them to array list.