Introduction
How can we add RadioButton
s to a DataGrid
in ASP.NET? And how can we use server side scripts when we click a RadioButton
on the grid? This is the (smart :) solution.
Using the code
Use this script to create RadioButton
s. When a RadioButton
is clicked, OnCheckedChanged
event will be fired. Write a server-side code to catch this event.
<asp:DataGrid id="dgOrnek" runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:RadioButton AutoPostBack=True
OnCheckedChanged="DetayGoster"
id="rbsira" Text='deneme' runat="server"/>
<ItemTemplate>
<TemplateColumn>
<Columns>
string sRbText="";
public void DetayGoster(object sender,EventArgs e) {
RadioButton rb = new RadioButton();
rb = (RadioButton) sender;
sRbText = rb.ClientID;
foreach (DataGridItem i in dgOrnek.Items)
{
rb = (RadioButton) i.FindControl ("rbsira");
rb.Checked = false;
if (sRbText==rb.ClientID)
{
rb.Checked = true;
txtSiraNo.Text = rb.Text.Trim();
}
}
}