how to find a dynamic control(radio button) inside a placeholder in gridview

endeavourford

New Member
i have gridview with 4 colums in col 1 i added a place holder and other 3 columns are boundfields. in col 1 im adding radio buttons dynamically using html code by which iam able to select only one radio button. is fine all working well , but the problem is iam unable to find the radio butoon conrtrol when a button is clicked which is outside the grid viewPlease help iam struck up with these problem from 4 daysThank you in advanceI used the following code.aspx File\[code\]<form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" onrowdatabound="GridView1_RowDataBound" > <AlternatingRowStyle BackColor="#CCCCCC" /> <Columns> <asp:TemplateField HeaderText="Select"> <ItemTemplate> <asp:PlaceHolder ID="ph" runat="server"></asp:PlaceHolder> </ItemTemplate> </asp:TemplateField> <asp:BoundField HeaderText="FIRST NAME" DataField="FNAME"/> <asp:BoundField HeaderText="LAST NAME" DataField="LNAME"/> <asp:BoundField HeaderText="EMAIL" DataField="EMAIL"/> <asp:BoundField HeaderText="AGE" DataField="AGE"/> </Columns> <FooterStyle BackColor="#CCCCCC" /> <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#F1F1F1" /> <SortedAscendingHeaderStyle BackColor="#808080" /> <SortedDescendingCellStyle BackColor="#CAC9C9" /> <SortedDescendingHeaderStyle BackColor="#383838" /> </asp:GridView> <asp:Button ID="btnSave" Text="Save" runat="server" onclick="btnSave_Click1" /> </form>\[/code\]Code Behind file\[code\] protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowIndex != -1 && e.Row.DataItem != null) { PlaceHolder holder = (PlaceHolder)e.Row.FindControl("ph"); String innerhtml = String.Format(" <input type='radio' name='sample' value='http://stackoverflow.com/questions/14517812/{0}' > ", "rb"); holder.Controls.Add(TemplateControl.ParseControl(innerhtml)); } } protected void btnSave_Click1(object sender, EventArgs e) { for (int i = 0; i < GridView1.Rows.Count; i++) { PlaceHolder holder = (PlaceHolder)GridView1.Rows.Cells[0].FindControl("ph"); RadioButton rbtn = holder.FindControl("rb") as RadioButton; if (rbtn.Checked == true) { Response.Write("<Script>alert('Radiocheck')</Script>"); } } }\[/code\]
 
Back
Top