前后代码<asp:GridView ID="gvAnserCard" runat="server" AutoGenerateColumns="false" SkinID="print">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table style="width:100%;">
<tr>
<td style="height: 18px">
第<asp:Label ID="labNum" runat="server" Text='<%# Eval("AnswerID") %>'></asp:Label>题</td>
</tr>
<tr>
<td>
<asp:RadioButtonList ID="rbtnList" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>D</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>后台我用foreach遍历的时候.
foreach (GridViewRow gRow in gvAnserCard.Rows)
{
Label labNum = (Label)gRow.FindControl("labNum");
RadioButtonList rbtnList = (RadioButtonList)gRow.FindControl("rbtnList");
cm.Parameters["@AnswerID"].Value = labNum.Text;
cm.Parameters["@UserAnswer"].Value = rbtnList.SelectedItem.Value;
}
怎么我数据库写进去的UserAnswer是空值...
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table style="width:100%;">
<tr>
<td style="height: 18px">
第<asp:Label ID="labNum" runat="server" Text='<%# Eval("AnswerID") %>'></asp:Label>题</td>
</tr>
<tr>
<td>
<asp:RadioButtonList ID="rbtnList" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>D</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>后台我用foreach遍历的时候.
foreach (GridViewRow gRow in gvAnserCard.Rows)
{
Label labNum = (Label)gRow.FindControl("labNum");
RadioButtonList rbtnList = (RadioButtonList)gRow.FindControl("rbtnList");
cm.Parameters["@AnswerID"].Value = labNum.Text;
cm.Parameters["@UserAnswer"].Value = rbtnList.SelectedItem.Value;
}
怎么我数据库写进去的UserAnswer是空值...
foreach(ListItem item in rbtnList.Items)
{ }