If you want to fill the RadioButtonList on GridView Row Click then please follow this
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="Name" HeaderText="Name" ItemStyle-Width="150" />
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
</asp:RadioButtonList>
<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");
GridView1.DataSource = dt;
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(GridView1, "Select$" + e.Row.RowIndex);
e.Row.Attributes["style"] = "cursor:pointer";
}
}
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
this.RadioButtonList1.Items.Clear();
int index = GridView1.SelectedRow.RowIndex;
for (int i = 0; i < GridView1.SelectedRow.Cells.Count; i++)
{
this.RadioButtonList1.Items.Add(new ListItem(GridView1.SelectedRow.Cells[i].Text, GridView1.SelectedRow.Cells[i].Text));
}
}
NameSpace:
using System.Data;
If you get the error of invalid postback then add
EnableEventValidation="false"
in your page directive.
Ref:http://aspsnippets.com/Articles/Add-Row-Click-event-to-GridView-Rows-in-ASPNet.aspx
Thank You.