Hi SUJAYS,
Refer below sample.
HTML
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" OnSelectedIndexChanged="gvCustomers_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="CustomerId" HeaderText="CustomerId" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
<asp:CommandField ShowSelectButton="true" />
</Columns>
</asp:GridView>
<br />
<asp:RadioButtonList ID="rblName" runat="server">
</asp:RadioButtonList>
Namespaces
C#
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Data
Imports System.Data.SqlClient
Code
C#
BEL.cs
public class BEL
{
private int _Id;
public int id
{
get
{
return _Id;
}
set
{
_Id = value;
}
}
}
BLL.cs
public class BLL
{
public DataTable GetData(BEL enities)
{
DAL dal = new DAL();
return dal.Data(enities);
}
}
DAL.cs
public DataTable Data(BEL enities)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT Country FROM Customers WHERE CustomerId = @Id", con))
{
cmd.Parameters.AddWithValue("@Id", enities.id);
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
}
}
CS.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("CustomerId", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
gvCustomers.DataSource = dt;
gvCustomers.DataBind();
rblName.DataSource = dt;
rblName.DataTextField = "Name";
rblName.DataValueField = "Name";
rblName.DataBind();
}
}
protected void gvCustomers_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = gvCustomers.SelectedRow;
int id = Convert.ToInt32(row.Cells[0].Text);
BEL entity = new BEL();
entity.id = Convert.ToInt32(id);
BLL bll = new BLL();
DataTable dt = bll.GetData(entity);
rblName.ClearSelection();
rblName.Items.FindByText(dt.Rows[0]["Name"].ToString()).Selected = true;
}
VB.Net
BELVB.vb
Private _Id As Integer
Public Property id As Integer
Get
Return _Id
End Get
Set(ByVal value As Integer)
_Id = value
End Set
End Property
BLLVB.vb
Public Function GetData(ByVal enities As BELVB) As DataTable
Dim dal As DALVB = New DALVB()
Return dal.Data(enities)
End Function
DALVB.vb
Public Function Data(ByVal enities As BELVB) As DataTable
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("SELECT CustomerId, Country, Name FROM Customers WHERE CustomerId = @Id", con)
cmd.Parameters.AddWithValue("@Id", enities.id)
Using da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
Return dt
End Using
End Using
End Using
End Function
VB.aspx.vb
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(2) {New DataColumn("CustomerId", GetType(Integer)), New DataColumn("Name", GetType(String)), New DataColumn("Country", GetType(String))})
dt.Rows.Add(1, "John Hammond", "United States")
dt.Rows.Add(2, "Mudassar Khan", "India")
dt.Rows.Add(3, "Suzanne Mathews", "France")
dt.Rows.Add(4, "Robert Schidner", "Russia")
gvCustomers.DataSource = dt
gvCustomers.DataBind()
rblName.DataSource = dt
rblName.DataTextField = "Name"
rblName.DataValueField = "Name"
rblName.DataBind()
End If
End Sub
Protected Sub gvCustomers_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim row As GridViewRow = gvCustomers.SelectedRow
Dim id As Integer = Convert.ToInt32(row.Cells(0).Text)
Dim entity As BELVb = New BELVb()
entity.id = Convert.ToInt32(id)
Dim bll As BLLVB = New BLLVB()
Dim dt As DataTable = bll.GetData(entity)
rblName.ClearSelection()
rblName.Items.FindByText(dt.Rows(0)("Name").ToString()).Selected = True
End Sub
Screenshot