Click here to Skip to main content
15,908,015 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all...
my code goes like :
HTML
RadioButton rbpres = new RadioButton();

                       
                        rbpres.ID = "rbone" + increm;
                        rbpres.Checked = true;
                        rbpres.GroupName = "g1" + increm;

                        RadioButton rbabs = new RadioButton();
                        rbabs.ID = "rbtwo" + increm;
                        rbabs.GroupName = "g1" + increm;
                        tc1.Controls.Add(rbpres);
                        tc1.Controls.Add(rbabs);
                        tr.Cells.Add(tc1);
                        tr.Cells.Add(tc1);
 tbl.Controls.Add(tr);
placeholder1.controls.add(tbl);

when am clicking button
i have written code like this

HTML
int increm = 0;
Control myControl = FindControlRecursive(PlaceHolder1, "rbone" + increm.ToString()) ;
                    RadioButton rbpres = this.Page.FindControl("rbone" + increm) as RadioButton;
                    RadioButton rbpres1 = (RadioButton)PlaceHolder1.NamingContainer.FindControl("rbone" + increm);
increm++;
and i was try to get the id of table like
 Table tbl = this.Page.FindControl("attentbl") as Table;
and i got check with this
Table tbl = PlaceHolder1.FindControl("attentbl") as Table;
 also same result object showing null value


but i never get the control every time it showing null value how can i get the id of dynamic radio button
can any one help me please am begging you
thanks in advance
Posted
Updated 3-Oct-11 23:13pm
v7
Comments
CodingLover 3-Oct-11 5:50am    
I cannot see a control with the name of rbpresent, can you?
tulasiram3975 3-Oct-11 8:57am    
UPDATED MY QUSTION KINDLY CHECK ONCE

1 solution

Hi,

try this code

C#
if (!IsPostBack)
   {
       RadioButton rdn = new RadioButton();
       rdn.ID = "rdbtn";
       rdn.Text = "ghgfh";
       contdiv.Controls.Add(rdn);
   }
   Control d = contdiv.FindControl("rdbtn");


In the above code,you've to use table id for searching radio button control.

instead of contdiv you've to place your table id

All the Best
 
Share this answer
 
Comments
tulasiram3975 3-Oct-11 8:59am    
HOW CAN I GET RUN TIME TABLE ID ON BUTTON CLICK
BUT I TRIED IN THIS WAY
Table tbl = this.Page.FindControl("tbl1") as Table;
IT WONT WORK OUT CAN YOU SHOW ME THE WAY TO GET IT
THANK YOU
Muralikrishna8811 3-Oct-11 9:28am    
you gave table id as runat="server"

in which control you are adding your radio button control

for eg.
you are adding your radio button control in table
then use
tableid.findcontrol("radiobuttonid")
tulasiram3975 3-Oct-11 9:42am    
ok i show you whole table
Table tbl = new Table();
tbl.ID = "tbl1";
tbl.Attributes.Add("runat", "server");
tbl.CellSpacing = 0;
tbl.CellPadding = 4;
TableHeaderRow thr = new TableHeaderRow();
TableHeaderCell thc = new TableHeaderCell();
Label lbrolno = new Label();
lbrolno.Text = "Roll No";
thc.Controls.Add(lbrolno);
thr.Cells.Add(thc);
tbl.Controls.Add(thr);
ViewState["nofsub"] = length;
// TableHeaderRow thr1 = new TableHeaderRow();
for (int n = 0; n < length; n++)
{
TableHeaderCell thc1 = new TableHeaderCell();
//thc1.ColumnSpan = 2;
Label lbsubjects = new Label();
lbsubjects.ID = "subject" + n;
lbsubjects.Text = sid.Split(',')[n];
thc1.Controls.Add(lbsubjects);
thr.Cells.Add(thc1);
}
tbl.Controls.Add(thr);
int increm = 0;
while (dr77.Read())
{
TableRow tr = new TableRow();
tr.BorderWidth = 1;
tr.BorderColor = Color.Black;
tr.BorderStyle = BorderStyle.Solid;
TableCell tc = new TableCell();
// tc.RowSpan = 2;
tc.BorderWidth = 1;
tc.BorderColor = Color.Black;
tc.BorderStyle = BorderStyle.Solid;
Label lbrolnocel = new Label();
lbrolnocel.Text = dr77["sno"].ToString();
tc.Controls.Add(lbrolnocel);
tr.Cells.Add(tc);
tbl.Controls.Add(tr);
// TableRow th1 = new TableRow();
for (int n = 0; n < length; n++)
{
TableCell tc1 = new TableHeaderCell();
//tc1.Width = 50;
// TableCell tc2 = new TableHeaderCell();
tc1.BorderWidth = 1;
tc1.BorderColor = Color.Black;
tc1.BorderStyle = BorderStyle.Solid;
RadioButton rbpres = new RadioButton();


rbpres.ID = "rbone" + increm;
rbpres.Checked = true;

rbpres.GroupName = "g1" + increm;

RadioButton rbabs = new RadioButton();
rbabs.ID = "rbtwo" + increm;


rbabs.GroupName = "g1" + increm;
tc1.Controls.Add(rbpres);

tc1.Controls.Add(rbabs);
tr.Cells.Add(tc1);
tr.Cells.Add(tc1);
increm++;
}

tbl.Controls.Add(tr);
}
PlaceHolder1.Controls.Add(tbl);
this is my dynamic table i was added to placeholder
first i need to get the dynamic table reference so that i was tried like
Table tbl = this.Page.FindControl("tbl1") as Table;
IT WONT WORK OUT i need to check weather radio button is checked or not
so that am try to get the radio button reference like
RadioButton rbpres = this.Page.FindControl("rbone" + increm) as RadioButton;
RadioButton rbpres1 = (RadioButton)PlaceHolder1.NamingContainer.FindControl("rbone" + increm);
but it is not finding radio button control it shows null value
waiting for you response
thank you
Muralikrishna8811 3-Oct-11 11:00am    
you've to write

PlaceHolder1.findcontrol("tbl1");
tulasiram3975 4-Oct-11 5:11am    
i have check with this also
Table tbl = PlaceHolder1.FindControl("tbl1") as Table;
same result the object showing null value
thank you for reply

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