本文介绍了使用复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个服务器表格
I have a server form
<asp:checkboxlist id="check1" runat="server">
<asp:listitem id="option1" runat="server" value="Auto Load" />
</asp:checkboxlist>
<input type="button" onclick="test();" runat="server" value="Alterar" />
然后我有这个
and then I have this
public string test(){
string msg = String.Empty;
if (check1.Items[0].Selected)
{
msg = check1.Items[0].Text + "<br />";
}
Response.Write(msg);
return "test" ;
}
但是什么也不会执行.我在做什么错?
But nothing is executed. What am I doing wrong?
推荐答案
<asp:Button id=Button1 Text="Click Me" onclick="Button1_Click" runat="server" />
后面的代码应该是
and the code behind should be
void Button1_Click(object Source, EventArgs e)
{
Response.Write("You clicked the button");
}
<input id="Button1" type="button" runat="server" value="Alterar" onserverclick="test"/>
并将您的服务器端代码更改为
and change your server side code as
protected void test(object sender, EventArgs e)
{
string msg = String.Empty;
if (check1.Items[0].Selected)
{
msg = check1.Items[0].Text + "<br />";
}
Response.Write(msg);
}
它将起作用.
It''ll work.
这篇关于使用复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!