<asp:DataList ID="DataList1" runat="server" BackColor="#CCCCCC" DataSourceID="SqlDataSource1" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" ForeColor="Black" style="margin-right: 260px" Width="720px">
<ItemTemplate>
<asp:Label ID="questionLabel" runat="server" Text='<%# Eval("question") %>' />
<br />
<asp:CheckBox ID="CheckBox1" runat="server" />
A:
<asp:Label ID="answer1Label" runat="server" Text='<%# Eval("answer1") %>' />
<br />
<asp:CheckBox ID="CheckBox2" runat="server" />
B:
<asp:Label ID="answer2Label" runat="server" Text='<%# Eval("answer2") %>' />
<br />
<asp:CheckBox ID="CheckBox3" runat="server" />
C:
<asp:Label ID="answer3Label" runat="server" Text='<%# Eval("answer3") %>' />
<br />
<asp:CheckBox ID="CheckBox4" runat="server" />
D:
<asp:Label ID="answer4Label" runat="server" Text='<%# Eval("answer4") %>' />
<br />
<br />
例如:
我希望在以下情况下将answer1labl
插入数据库中的student_answer
列:checkbox1.checked == true
。
答案 0 :(得分:0)
在按钮单击中,您可以这样做,
protected void btnSave_Click(object sender, EventArgs e)
{
foreach (DataListItem item in DataList1.Items)
{
CheckBox cb = (CheckBox)item.FindControl("CheckBox1");
if (cb.Checked)
{
string text = ((Label)item.FindControl("answer1Label")).Text;
//save code
}
}
}