在ASP.NET中的GridView中使用RadioButton的问题(Problem with usage of RadioButton in GridView in ASP.NET)

编程入门 行业动态 更新时间:2024-10-28 18:27:05
在ASP.NET中的GridView中使用RadioButton的问题(Problem with usage of RadioButton in GridView in ASP.NET) <asp:TemplateField HeaderText="Select One"> <ItemTemplate> <input name="MyRadioButton" type="radio" /> </ItemTemplate> </asp:TemplateField>

aspx.cs

protected void Button1_Click(object sender, EventArgs e) { foreach (GridViewRow di in GridView1.Rows) { RadioButton rad = (RadioButton)di.FindControl("MyRadioButton"); //Giving Error:Object reference not set to an instance of an object. if (rad.Checked&&rad!=null) { s = di.Cells[1].Text; } } Response.Redirect("applicants.aspx?form=" +s); }

我无法获得在RadioButton选择的行。 你能帮我解决这个问题吗?

<asp:TemplateField HeaderText="Select One"> <ItemTemplate> <input name="MyRadioButton" type="radio" /> </ItemTemplate> </asp:TemplateField>

aspx.cs

protected void Button1_Click(object sender, EventArgs e) { foreach (GridViewRow di in GridView1.Rows) { RadioButton rad = (RadioButton)di.FindControl("MyRadioButton"); //Giving Error:Object reference not set to an instance of an object. if (rad.Checked&&rad!=null) { s = di.Cells[1].Text; } } Response.Redirect("applicants.aspx?form=" +s); }

I couldn't get the row which is selected in RadioButton. Can you help me with this please.

最满意答案

您只能在服务器端控件上使用FindControl 。 用ASP.NET单选按钮替换<input> HTML元素,例如:

<asp:RadioButton ID="MyRadioButton" runat="server" ... />

You can only use FindControl with server-side controls. Replace your <input> HTML element with an ASP.NET radio button, e.g:

<asp:RadioButton ID="MyRadioButton" runat="server" ... />

更多推荐

本文发布于:2023-08-06 08:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1447809.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:GridView   NET   ASP   usage   Problem

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!