HTML:
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
runat="server" AutoGenerateColumns="false" OnRowDataBound="OnRowDataBound" OnSelectedIndexChanged="OnSelectedIndexChanged">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="150" />
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
Id
</td>
<td>
<asp:TextBox ID="txtId" runat="server" />
</td>
</tr>
<tr>
<td>
Name
</td>
<td>
<asp:TextBox ID="txtName" runat="server" />
</td>
</tr>
<tr>
<td>
Counrty
</td>
<td>
<asp:DropDownList ID="ddlCountry" runat="server">
</asp:DropDownList>
</td>
</tr>
</table>
<asp:LinkButton ID="lnkDummy" runat="server"></asp:LinkButton>
</div>
</form>
C#:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id"), new DataColumn("Name"), new DataColumn("Country") });
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");
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
}
protected void OnRowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
e.Row.Attributes["style"] = "cursor:pointer";
}
}
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
this.txtId.Text = this.GridView1.SelectedRow.Cells[0].Text;
this.txtName.Text = this.GridView1.SelectedRow.Cells[1].Text;
this.ddlCountry.Items.Clear();
this.ddlCountry.Items.Add(new ListItem(this.GridView1.SelectedRow.Cells[2].Text, this.GridView1.SelectedRow.Cells[2].Text));
}
Thank You.