日期:2014-05-17 浏览次数:20478 次
<%@ Page Language="C#" EnableViewState="false" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { } } protected void Fx_hjys_SelectedIndexChanged(object sender, EventArgs e) { string _hjys = null; string temp = "0"; for (int i = 0; i < this.Fx_hjys.Items.Count; i++) { if (this.Fx_hjys.Items[i].Selected) { _hjys += "【" + this.Fx_hjys.Items[i].Text + "】"; temp = Convert.ToString(Convert.ToInt32(temp) + Convert.ToInt32(this.Fx_hjys.Items[i].Value)); } } Response.Write(_hjys); } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:CheckBoxList ID="Fx_hjys" runat="server" RepeatDirection="Vertical" RepeatColumns="4" AutoPostBack="true" OnSelectedIndexChanged="Fx_hjys_SelectedIndexChanged"> <asp:ListItem Value="5">暴雨</asp:ListItem> <asp:ListItem Value="5">冰雪</asp:ListItem> <asp:ListItem Value="5">大风</asp:ListItem> <asp:ListItem Value="5">泥石流</asp:ListItem> <asp:ListItem Value="5">地震</asp:ListItem> <asp:ListItem Value="5">高温</asp:ListItem> </asp:CheckBoxList> </form> </body> </html>
------解决方案--------------------
你的代码
protected void Fx_sbys_SelectedIndexChanged(object sender, EventArgs e)
{
string _sbys = "";
string temp1 = "0";
Response.Write("xx");
for (int i = 0; i < this.Fx_sbys.Items.Count; i++)
{
if (this.Fx_sbys.Items[i].Selected)
{
_sbys += "【" + this.Fx_sbys.Items[i].Text + "】";
temp1 = Convert.ToString(Convert.ToInt32(temp1) + Convert.ToInt32(this.Fx_sbys.Items[i].Value));
}
}
this.fx_sbysmc.Text = _sbys;
this.Fx_sbysz.Text = temp1;
}
另外,Value不能是重复的内容,如
<tr>
<td class="rtd" colspan="4">
<asp:CheckBoxList ID="Fx_hjys" runat="server" RepeatDirection="Vertical" RepeatColumns="4"
OnSelectedIndexChanged="Fx_hjys_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Value="1">暴雨</asp:ListItem>
<asp:ListItem Value="2">冰雪</asp:ListItem>
<asp:ListItem Value="3">大风</asp:ListItem>
<asp:ListItem Value="4">泥石流</asp:ListItem>
<asp:ListItem Value="5">地震</asp:ListItem>
<asp:ListItem Value="6">高温</asp:ListItem>
</asp:CheckBoxList>
</td>