65.9K
CodeProject is changing. Read more.
Home

Adding and Using RadioButton to DataGrid in ASP.NET

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.75/5 (19 votes)

Apr 13, 2004

viewsIcon

153325

Adding and using RadioButton to DataGrid in ASP.NET.

Introduction

How can we add RadioButtons 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 RadioButtons. 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(); 
  // if you want to get a property of the selected id
         }
     }
  }
Adding and Using RadioButton to DataGrid in ASP.NET - CodeProject