Jump to content


saving data of dynamic radio button list


1 reply to this topic

#1 kablitz

    Young Padawan

  • Members
  • Pip
  • 5 posts

Posted 05 July 2007 - 04:42 AM

hi im kinda new to ASP.NET and im quite stumped right now. im creatting an application where i retrieve data from a database then render controls and put the data i retrieved into labels and radio button lists (labels are for questions and radiobuttonlists for options). im trying to show the summary of the selected options but i dont know how i will retrieve the selected value of the radio buttons. please help me.. >_<

here is my code:

protected void Page_Load(object sender, EventArgs e) 

{







if(Profile.AnsweredSurvey == "true") 

{



Response.Redirect("~/survey/survey-finish.aspx"); 

}



cDatabase objData = new cDatabase(); 

int QuestionCount = objData.getQuestionCount();



System.Web.UI.WebControls.Label lbl1; 

System.Web.UI.WebControls.RadioButtonList rbl1;



for (int i = 1; i < (QuestionCount + 1); i++) 

{



string lblID = "lblQuestion" + i; 

string rblID = "rblOption" + i;



lbl1 = new Label(); 

lbl1.ID = lblID;



string QuestionID = objData.getQuestionID(i);string QuestionText = objData.getQuestion(i); 

lbl1.Text = QuestionText;



PlaceHolder1.Controls.Add(lbl1);



rbl1 = new RadioButtonList(); 

rbl1.ID = rblID;



rbl1.RepeatDirection = RepeatDirection.Horizontal; 

int OptionCount = objData.getOptionCount(QuestionID);



string[] OptionNum = new string[OptionCount]; 

string[] OptionText = new string[OptionCount];



for (int j = 0; j < OptionCount; j++) 

{



OptionNum[j] = objData.getOptionID(OptionCount, j, QuestionID);



OptionText[j] = objData.getOptions(OptionNum[j].ToString(), OptionCount, j);



rbl1.Items.Add(OptionText[j]);



}



PlaceHolder1.Controls.Add(rbl1);



}





}


Edited by kablitz, 05 July 2007 - 04:43 AM.


#2 U1

    Young Padawan

  • Members
  • Pip
  • 245 posts

Posted 06 July 2007 - 06:31 PM

With the RadioButtonList control you can bind the SelectedValue property to your Parameter.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users