Gridview与无线电列,无线电id问题

时间:2009-07-10 19:28:35

标签: c# asp.net

我有一个gridview,我为它放了一个无线电列。但无线电ids不是唯一的。 我读了 http://www.asp.net/Learn/data-access/tutorial-51-cs.aspx http://shawpnendu.blogspot.com/2009/02/problem-to-group-radio-button-across.html http://aspnet.4guysfromrolla.com/articles/122602-1.aspx 但它们很复杂。 你有其他解决方案,c#代码落后了吗?我还尝试使用代码后面的函数给出唯一的id,但ID ='<%#function(...)%>'不被允许。 提前谢谢

有gridview代码:

<asp:GridView ID="gridView_stLists"
              runat="server"
              AutoGenerateColumns="False"
              CellPadding="3"
              BorderStyle="NotSet"
              CssClass="table_layout"
              Width="500">
           <RowStyle CssClass="table_body" />
              <Columns>
                 <asp:TemplateField HeaderStyle-Width="20">
                     <ItemTemplate>
                       <asp:RadioButton ID="rdBtn_stdl" runat="server"
                             OnCheckedChanged="rdBtn_stdl_CheckedChanged"
                             AutoPostBack="True"
                             GroupName="stdl" value='<%# Eval("uri") %>' />
                     </ItemTemplate>

我认为无线电必须在ID =“rdBtn_stdl”部分中具有不同的ID

3 个答案:

答案 0 :(得分:0)

不完全确定你的问题是什么,但现在就去了。

如果你需要在GridViewRow中找到一个RadioButton,首先得到该行,然后使用FindControl()

GridViewRow myRow = GridView1.Rows[index];
RadioButton myRadioButton = (RadioButton)myRow.FindControl("nameOfRadioButton")

您可以反向执行此操作(例如,如果需要处理事件RadioButton1_CheckedChanged),首先将对象发送者强制转换为RadioButton,然后将RadioButton.Parent.Parent强制转换为GridViewRow,从中可以获取索引。 / p>

问题:

你添加了一个模板列的列,你放置了一个RadioButton?我的两个解决方案只适用于这种情况。

答案 1 :(得分:0)

单选按钮需要具有相同的name属性。 唯一。这就是浏览器如何分组它们的方式。

答案 2 :(得分:0)