Hi KatieNgoc,
Refer below sample.
HTML
<asp:RadioButtonList ID="rbtRole1" runat="server" RepeatDirection="Vertical" CssClass="radio btn-group-justified"
Font-Bold="true" Font-Size="Large">
<asp:ListItem>Service Seeker</asp:ListItem>
<asp:ListItem>Service Provider</asp:ListItem>
<asp:ListItem>Company</asp:ListItem>
<asp:ListItem>Job Seeker</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:RadioButtonList ID="rbtRole2" runat="server" RepeatDirection="Vertical" CssClass="radio btn-group-justified"
Font-Bold="true" Font-Size="Large">
<asp:ListItem>Service Seeker</asp:ListItem>
<asp:ListItem>Service Provider</asp:ListItem>
<asp:ListItem>Company</asp:ListItem>
<asp:ListItem>Job Seeker</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:RadioButtonList ID="rbtRole3" runat="server" RepeatDirection="Vertical" CssClass="radio btn-group-justified"
Font-Bold="true" Font-Size="Large">
<asp:ListItem>Service Seeker</asp:ListItem>
<asp:ListItem>Service Provider</asp:ListItem>
<asp:ListItem>Company</asp:ListItem>
<asp:ListItem>Job Seeker</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:Button Text="Save" runat="server" OnClick="Save" />
<br />
<asp:GridView runat="server" ID="gvRoles" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Role1" HeaderText="Role1" />
<asp:BoundField DataField="Role2" HeaderText="Role2" />
<asp:BoundField DataField="Role3" HeaderText="Role3" />
</Columns>
</asp:GridView>
Namespaces
C#
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
VB.Net
Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration
Code
C#
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BindGrid();
}
}
private void BindGrid()
{
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT Role1,Role2,Role3 FROM Common_regn2", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
gvRoles.DataSource = dt;
gvRoles.DataBind();
}
}
}
}
protected void Save(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO Common_regn2(Role1,Role2,Role3) VALUES(@Role1,@Role2,@Role3)", con))
{
cmd.Parameters.AddWithValue("@Role1", rbtRole1.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Role2", rbtRole2.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Role3", rbtRole3.SelectedItem.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
BindGrid();
}
VB.Net
Private constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
BindGrid()
End If
End Sub
Private Sub BindGrid()
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("SELECT Role1,Role2,Role3 FROM Common_regn2", con)
Using da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
gvRoles.DataSource = dt
gvRoles.DataBind()
End Using
End Using
End Using
End Sub
Protected Sub Save(ByVal sender As Object, ByVal e As EventArgs)
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("INSERT INTO Common_regn2(Role1,Role2,Role3) VALUES(@Role1,@Role2,@Role3)", con)
cmd.Parameters.AddWithValue("@Role1", rbtRole1.SelectedItem.Text)
cmd.Parameters.AddWithValue("@Role2", rbtRole2.SelectedItem.Text)
cmd.Parameters.AddWithValue("@Role3", rbtRole3.SelectedItem.Text)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
BindGrid()
End Sub
Screenshot