Click here to Skip to main content
15,915,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I will describe the senario before i give the problem:
i use dynamical way to radio button list control this list contain many radio button
the problem is that i can't catch the selected value on the POSTBACK

I NEED THE SOLUTION USING Request.Form[id];--> this return the id of radiobutton list without the selected value
Posted

I found the solution by using Request.FOrm[ID] all what i need is to define the eadio button in the same group having same groupname but not the same radiobutton value ex:
C#
public RadioButtonControl (String Question, String[] tabRadioButton)
           {

           Label ques = new Label();
           ques.Text = Question;

           Table tabl = new Table();
           TableRow tablRow = new TableRow();
           TableCell tablCell = new TableCell();
           tablCell.Controls.Add(ques);

           tablRow.Cells.Add(tablCell);
           tabl.Rows.Add(tablRow);

           this.Controls.Add(tabl);

           RadioButtonList list1 = new RadioButtonList();
           list1.RepeatLayout = RepeatLayout.Table;
           list1.BorderWidth = 2 ;

           foreach(string s in tabRadioButton)
           {
               ListItem li = new ListItem();
               RadioButton tb = new RadioButton();
                   tb.Text = s;
               tb.GroupName = Question;
                   li.Text = tb.Text;
                   li.Value = tb.Text;
                   list1.Items.Add(li);

           }

           list1.RepeatDirection =  RepeatDirection.Horizontal;
           list1.RepeatColumns = 3;
           UsedRadioButtonList = list1;//for set and get

           this.Controls.Add(list1);
       }


      //this method will get the selected value
      public String GetSelectedValueById(string Id,HttpRequest Request)
       {
          string d ="";
          String[] st = Id.Split('_');
          d = Id + "$ctl01";
           return Request.Form[d];
       }


Happy coding ;)
 
Share this answer
 
v4
Hi ,
To bind the RaidButton u have to implement Radiolist_DataBound and loop through the items . I made solution but i didnt need use Request.form coz i create the Radiolist and bind it in one step .
Code behind :
C#
protected System.Web.UI.WebControls.RadioButtonList raid;
   DataClassesDataContext db = new DataClassesDataContext();
   protected void Page_Load(object sender, EventArgs e)
   {
   }
   int countTimes = 0;
   protected void Button1_Click(object sender, EventArgs e)
   {
       if (ViewState["countTimes"] == null)
       {
           countTimes = 1;
       }
       else
       {
           countTimes = Convert.ToInt32(ViewState["countTimes"]);
       }

       for (int i = 0; i < countTimes; i++)
       {
           raid = new RadioButtonList();
           raid.ID = "raid" + i;



           form1.Controls.Add(raid);


       }
       countTimes = countTimes + 1;

       ViewState.Add("countTimes", countTimes);
       var result = from x in db.cates
                    select new { x.chk, x.id };
       raid.DataSource = result;
       raid.DataTextField = "chk";
       raid.DataValueField = "chk";

       raid.DataBind();
       raid_DataBound(raid, new EventArgs());
   }

   void raid_DataBound(object sender, EventArgs e)
   {
       foreach (ListItem item in raid.Items)
       {
           item.Selected = bool.Parse(item.Value);
       }
   }

ASP.NET
<div>
          <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br />
 </div>

Best Regards
M.mitwalli
 
Share this answer
 
Comments
bashar Haydar 2-Apr-12 3:11am    
i still work on little demo, i don't have access to any data base, i get my data from simple string table sow It's not working but thx any way
Mohamed Mitwalli 2-Apr-12 5:26am    
your welcome :)

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