How to Bind Radio Button Control inside the Grid View control in ASP.NET

Binding process of control is same , You can bind all of controls from this method. In previous article we have  already discussed about Bind GridView in In this example we have four radio buttons and one label control. Bind the text  of  radio button use <%# Eval(" Attribute of table") %> .
How to Bind Radio Button Control inside the Grid View control in ASP.NET

<asp:GridView ID="GridView2" runat="server" Height="202px" Width="624px" AutoGenerateColumns ="False" ShowHeader="False" AllowPaging="True">
        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Question") %>'></asp:Label><br />
            <asp:RadioButton ID="R1" runat="server" Text ='<%# Eval ("Answer-1") %>' GroupName ="g1" />
         <asp:RadioButton ID="R2" runat="server" Text ='<%# Eval ("Answer-2") %>' GroupName ="g1" />
         <asp:RadioButton ID="R3" runat="server" Text ='<%# Eval ("Answer-3") %>' GroupName ="g1"/>
         <asp:RadioButton ID="R4" runat="server" Text ='<%# Eval ("Answer-4") %>' GroupName ="g1"/>
    <ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" />
</asp:TemplateField></Columns> </asp:GridView>

Codebehind code

 private void Bindabledata()
        SqlConnection con = new SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "select * from [Question_Table]";
        cmd.Connection = con;
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        GridView2.DataSource = ds;


Code generate the following output


Popular posts from this blog

difference between structure and union in C Language

Difference between Linear search and Binary Search in c language

Difference between static and dynamic websites