DataList中RadioButton的使用问题
C#:protectedvoidsubmit_Click(objectsender,EventArgse){inti;for(i=1;i<=5;i++){RadioBut...
C#:
protected void submit_Click(object sender, EventArgs e)
{
int i;
for (i = 1; i <= 5; i++)
{
RadioButton select = DataList1.Items[0].FindControl("RadioButton"+i) as RadioButton;
Response.Write(select.Checked.ToString());
}
}
aspx:
<form id="form1" runat="server">
<div>
<div><asp:Label ID="title" runat="server"></asp:Label></div>
<asp:DataList ID="DataList1" runat="server" DataKeyField="testitemid">
<ItemTemplate>
<asp:Label ID="itemnameLabel" runat="server" Text='<%# Eval("itemname") %>'></asp:Label>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName='<%# Eval("itemname") %>' Text='<%# Eval("select1") %>' Visible='<%# Eval("select1") != System.DBNull.Value %>' style='<%# "display:" + (Eval("select1") != System.DBNull.Value ? "block" : "none") %>'/>
<asp:RadioButton ID="RadioButton2" runat="server" GroupName='<%# Eval("itemname") %>' Text='<%# Eval("select2") %>' Visible='<%# Eval("select2") != System.DBNull.Value %>' style='<%# "display:" + (Eval("select2") != System.DBNull.Value ? "block" : "none") %>'/>
<asp:RadioButton ID="RadioButton3" runat="server" GroupName='<%# Eval("itemname") %>' Text='<%# Eval("select3") %>' Visible='<%# Eval("select3") != System.DBNull.Value %>' style='<%# "display:" + (Eval("select3") != System.DBNull.Value ? "block" : "none" )%>' />
<asp:RadioButton ID="RadioButton4" runat="server" GroupName='<%# Eval("itemname") %>' Text='<%# Eval("select4") %>' Visible='<%# Eval("select4") != System.DBNull.Value %>' style='<%# "display:" + (Eval("select4") != System.DBNull.Value ? "block" : "none" )%>'/>
<asp:RadioButton ID="RadioButton5" runat="server" GroupName='<%# Eval("itemname") %>' Text='<%# Eval("select5") %>' Visible='<%# Eval("select5") != System.DBNull.Value %>' style='<%# "display:" + (Eval("select5") != System.DBNull.Value ? "block" : "none" )%>' />
</ItemTemplate>
<SeparatorTemplate><hr /></SeparatorTemplate>
</asp:DataList>
</div>
<asp:Label ID="statement" runat="server"></asp:Label><br />
<asp:Button ID="submit" runat="server" Text="查看结果" OnClick="submit_Click" />
</form>
怎么我单击submit后显示的全是FALSE
这里的判断有问题吗? 展开
protected void submit_Click(object sender, EventArgs e)
{
int i;
for (i = 1; i <= 5; i++)
{
RadioButton select = DataList1.Items[0].FindControl("RadioButton"+i) as RadioButton;
Response.Write(select.Checked.ToString());
}
}
aspx:
<form id="form1" runat="server">
<div>
<div><asp:Label ID="title" runat="server"></asp:Label></div>
<asp:DataList ID="DataList1" runat="server" DataKeyField="testitemid">
<ItemTemplate>
<asp:Label ID="itemnameLabel" runat="server" Text='<%# Eval("itemname") %>'></asp:Label>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName='<%# Eval("itemname") %>' Text='<%# Eval("select1") %>' Visible='<%# Eval("select1") != System.DBNull.Value %>' style='<%# "display:" + (Eval("select1") != System.DBNull.Value ? "block" : "none") %>'/>
<asp:RadioButton ID="RadioButton2" runat="server" GroupName='<%# Eval("itemname") %>' Text='<%# Eval("select2") %>' Visible='<%# Eval("select2") != System.DBNull.Value %>' style='<%# "display:" + (Eval("select2") != System.DBNull.Value ? "block" : "none") %>'/>
<asp:RadioButton ID="RadioButton3" runat="server" GroupName='<%# Eval("itemname") %>' Text='<%# Eval("select3") %>' Visible='<%# Eval("select3") != System.DBNull.Value %>' style='<%# "display:" + (Eval("select3") != System.DBNull.Value ? "block" : "none" )%>' />
<asp:RadioButton ID="RadioButton4" runat="server" GroupName='<%# Eval("itemname") %>' Text='<%# Eval("select4") %>' Visible='<%# Eval("select4") != System.DBNull.Value %>' style='<%# "display:" + (Eval("select4") != System.DBNull.Value ? "block" : "none" )%>'/>
<asp:RadioButton ID="RadioButton5" runat="server" GroupName='<%# Eval("itemname") %>' Text='<%# Eval("select5") %>' Visible='<%# Eval("select5") != System.DBNull.Value %>' style='<%# "display:" + (Eval("select5") != System.DBNull.Value ? "block" : "none" )%>' />
</ItemTemplate>
<SeparatorTemplate><hr /></SeparatorTemplate>
</asp:DataList>
</div>
<asp:Label ID="statement" runat="server"></asp:Label><br />
<asp:Button ID="submit" runat="server" Text="查看结果" OnClick="submit_Click" />
</form>
怎么我单击submit后显示的全是FALSE
这里的判断有问题吗? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询