Sunday 2 September 2012

radio button in gridview

.cs code:

 your going to use a grid view and u want to put a radio button on a TemplateField to act as a pointer to your selection just use this code on the rbSelector_CheckedChanged()..






protected void rbSelector_CheckedChanged(object sender, System.EventArgs e)
        {

            //Clear the existing selected row
            foreach (GridViewRow oldrow in GVLotList.Rows)
            {
                ((RadioButton)oldrow.FindControl("rbSelector")).Checked = false;
            }

            //Set the new selected row
            RadioButton rb = (RadioButton)sender;
            GridViewRow row = (GridViewRow)rb.NamingContainer;
            ((RadioButton)row.FindControl("rbSelector")).Checked = true;
        }


aspx page code:


 <asp:TemplateField HeaderStyle-Width="30px">
       <ItemTemplate>
        <asp:RadioButton ID="rbSelector" AutoPostBack="true" runat="server"                  OnCheckedChanged="rbSelector_CheckedChanged" />
        </ItemTemplate>
   </asp:TemplateField>

No comments:

Post a Comment

Contact Us:

Email:

Vinodkumar434@gmail.com,
vinodtechnosoft@gmail.com

Skype Name:

vinodtechnosoft