在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" ... />更多推荐
发布评论