我在 gridview 中有 RadioButton ,我使用图片按钮更改为下一页,并在当前页面中使用 RadioButton 值有一个隐藏的领域。
但是当我尝试在RadioButton(隐藏字段)中检索所选值时,它返回空字符串。
有人可以帮助我吗?
我的代码如下。
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvr in GridView1.Rows)
{
RadioButton rb = (RadioButton)gvr.FindControl("RadioButton1");
if (rb.Checked)
{
HiddenField hf = (HiddenField)gvr.FindControl("HiddenField1");
Response.Write(rb.Text.ToString() + "<br />" + hf.ToString());
}
else
{
Response.Write("empty<br />");
}
}
}
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton ID="RadioButton1" runat="server" onclick="RadioCheck(this);" />
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%#Eval("Area").ToString()%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:ImageButton ID="btnEdit" runat="server" OnClick="Button1_Click" ImageUrl="/Images/button.gif" />
答案 0 :(得分:0)
第9行出错
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvr in GridView1.Rows)
{
RadioButton rb = (RadioButton)gvr.FindControl("RadioButton1");
if (rb.Checked)
{
HiddenField hf = (HiddenField)gvr.FindControl("HiddenField1");
Response.Write(rb.Text.ToString() + "<br />" + hf.Value.ToString());
}
else
{
Response.Write("empty<br />");
}
}
}