65.9K
CodeProject 正在变化。 阅读更多。
Home

在 ASP.NET DataGrid 中添加和使用 RadioButton

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.75/5 (19投票s)

2004年4月13日

viewsIcon

153843

在 ASP.NET DataGrid 中添加和使用 RadioButton。

引言

我们如何在 ASP.NET 的 DataGrid 中添加 RadioButton?以及当我们在网格上的 RadioButton 被点击时,如何使用服务器端脚本? 这是(一个聪明的 :) 解决方案。

使用代码

使用此脚本创建 RadioButton。当一个 RadioButton 被点击时,OnCheckedChanged 事件将被触发。编写服务器端代码来捕获此事件。

<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
         }
     }
  }
© . All rights reserved.