Click here to Skip to main content
15,905,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi frnds,

I am using datalist for showing datas. Datas are test questions with 4 options.I have 50 questions displaying in datalist.

By using ItemDataBound event - i am making visible only one question with 4 options to user. Remaining questions are invisible . In the Itemdatabound event - i am assigning id to the radio buttons. but also id is not assigned to the datalist ,it showing different id.
C#
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {                
HiddenField HdSlNo = (HiddenField)e.Item.FindControl("HdSlNo");
                RadioButton Option1 = (RadioButton)e.Item.FindControl("Option1");
                RadioButton Option2 = (RadioButton)e.Item.FindControl("Option2");
                RadioButton Option3 = (RadioButton)e.Item.FindControl("Option3");
                RadioButton Option4 = (RadioButton)e.Item.FindControl("Option4");
                RadioButton Option5 = (RadioButton)e.Item.FindControl("Option5");
                
                Option1.ID = "rdbtnoption1_" + HdSlNo.Value.ToString();
                Option2.ID = "rdbtnoption2_" + HdSlNo.Value.ToString();
                Option3.ID = "rdbtnoption3_" + HdSlNo.Value.ToString();
                Option4.ID = "rdbtnoption4_" + HdSlNo.Value.ToString();
                Option5.ID = "rdbtnoption5_" + HdSlNo.Value.ToString();
}



Thanks,
Suresh
Posted

On itemDataBound event just assign the question id and option id to the radio button controls.
Or you can use for loop to iterate over the options/questions and assign the item index value to the control.

Bear in mind that different IDs will appear because the controls inside each Data List item will need a unique ClientID so the html is generated correctly and view state works.
 
Share this answer
 
Comments
itsureshuk 11-Jan-14 0:38am    
in itemdatabound and in itemrowcreated both events i assigned but it not reflecting
itsureshuk 11-Jan-14 1:01am    
Hi I got a solution by assigning properties of the control as ClientIDMode="Static" . I am getting assigned ID also.Whether it will affect anywhere?
  • It is possible to create a new dynamic control and to rename it
  • but the DataList will not allow you to rename the existing control ID that is defined inside the ItemTemplate
    have a look at this http://stackoverflow.com/a/18976091[^]
 
Share this answer
 
Comments
itsureshuk 11-Jan-14 1:01am    
Hi I got a solution by assigning properties of the control as ClientIDMode="Static" . I am getting assigned ID also.Whether it will affect anywhere?
Karthik_Mahalingam 11-Jan-14 4:29am    
it will have an impact over other javascript function. unless you are not using ClientID in the javascript.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900