日期:2014-05-18 浏览次数:20472 次
foreach (GridViewRow row in GridViewDemo.Rows) { if (row.RowType == DataControlRowType.DataRow) { foreach(Control obj in row.Controls) { if (obj.GetType().BaseType.Name.ToUpper().Contains("RADIOBUTTON")) { } } } }
foreach (GridViewRow row in GridViewDemo.Rows) { if (row.RowType == DataControlRowType.DataRow) { RadioButton rb = row.FindControl("控件名称1"); RadioButton rb = row.FindControl("控件名称2"); RadioButton rb = row.FindControl("控件名称3"); //得到三个单选按钮后就可以判断了 //判断代码略... } }
------解决方案--------------------
按照lz的意思作了一个,看看是不是这样,我试了可以显示出被选按钮的ID
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"> <Columns> <asp:TemplateField HeaderText="Select" ShowHeader="False"> <ItemTemplate> <asp:RadioButton ID="RadioButton1" runat="server" Text="RadioButton1" GroupName="RadioGroup" /> <asp:RadioButton ID="RadioButton2" runat="server" Text="RadioButton2" GroupName="RadioGroup" /> <asp:RadioButton ID="RadioButton3" runat="server" Text="RadioButton3" GroupName="RadioGroup" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="insertTime" HeaderText="Time" /> </Columns> </asp:GridView> <br /> <asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />