Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Adding and Using RadioButton to DataGrid in ASP.NET

0.00/5 (No votes)
9 May 2004 2  
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

         }
     }
  }

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here