大家好,我使用网格视图将多行记录插入数据库。这就是我的网格视图的样子
问题是可以选择所有单选按钮,我只需要为每一行选择一个单选按钮...... 我的 Web 表单的工作方式是用户必须使用单选按钮从两个文本框中选择正确答案,然后我必须将选中的答案提交到数据库。这可能吗?
aspx:`
<asp:ButtonField Text="SingleClick" CommandName="SingleClick"
Visible="False" />
<asp:TemplateField HeaderText="Question">
<ItemTemplate>
<br />
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Answer">
<ItemTemplate>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RadioButton ID="RadioButton1" runat="server" />
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RadioButton ID="RadioButton2" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<FooterTemplate>
<asp:Button ID="btnAdd" runat="server" Text="+" onclick="btnAdd_Click1" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>`
后面的代码:
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
//Clear the existing selected row
foreach (GridViewRow oldrow in GridView1.Rows)
{
((RadioButton)oldrow.FindControl("RadioButton1")).Checked = false;
}
//Set the new selected row
RadioButton rb = (RadioButton)sender;
GridViewRow row = (GridViewRow)rb.NamingContainer;
((RadioButton)row.FindControl("RadioButton1")).Checked = true;
}