Click here to Skip to main content
16,012,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m working on asp.net website. i want to create dynamic table
Each row of table will contain one text box and one radiobutton.
The first row is design part and i have created it. Also i have given one add button at bottom of table to add new row.
I m able to add textbox dynamically at add button click and maintain it's viewstate. I want to maintain the viewstate because data in all rows i need to save in datatbse.
But i not getting how to add radiobutton dynamically add radiobutton and maintain it's view state. These all radiobuttons should belong to same set of radiobuttons
Posted
Updated 4-Apr-12 16:46pm
v2
Comments
Nilesh Patil Kolhapur 5-Apr-12 0:40am    
give some code.
Mohamed Mitwalli 25-Apr-12 15:22pm    
Did it work with you ?

Hi ,
Try this will Guide you .

C#
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++)
      {
          TableRow tr = new TableRow();

          TableCell cl = new TableCell();
          TableCell cl2 = new TableCell();
          RadioButton raid = new RadioButton();
          raid.ID = "raid" + i;
          TextBox txt = new TextBox();
          txt.ID = "txt"+i;

            cl.Controls.Add(txt);
          cl2.Controls.Add(raid);

            tr.Controls.Add(cl);
            tr.Controls.Add(cl2);
            Table1.Controls.Add(tr);
      }

      countTimes = countTimes + 1;
      ViewState.Add("countTimes", countTimes);

  }


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

      <asp:Table ID="Table1" runat="server">
      </asp:Table>
  </div>

Best Regards
M.Mitwalli
 
Share this answer
 
Comments
Member 8081020 7-Apr-12 2:09am    
Thanks for help
Mohamed Mitwalli 8-Apr-12 4:30am    
your welcome by the way if it did help you mark it as an answer
We can get value of dynamic control By Using Request.Form["control_id");
Re Create Controls For every post-back so that no need to maintain viewstate here
 
Share this answer
 
Comments
Member 8081020 7-Apr-12 2:09am    
Thanks for help
Mohamed Mitwalli 8-Apr-12 2:32am    
did it help you ??
C#
protected void Page_Load(object sender, EventArgs e)
  {
              RadioButtonList radBtnList = new RadioButtonList();
              radBtnList.Items.Add(new ListItem("Delete","1"));
              radBtnList.Items.Add(new ListItem("Keep", "0"));
              //radBtnList.ID
              radBtnList.AutoPostBack = true;
              radBtnList.RepeatDirection = RepeatDirection.Horizontal;
              Panel1.Controls.Add(radBtnList);
  }



}
 
Share this answer
 
v2
Comments
Member 8081020 7-Apr-12 2:09am    
Thanks for help

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