metabuilder检查列表框选中的索引已更改,无法在服务器上运行

时间:2012-04-25 09:49:15

标签: c# asp.net listbox

我正在使用元构建器检查列表框,并且他们选择的索引在本地更改正常工作但不在服务器端工作。请帮我修复这个错误。我的部分代码在这里..

    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{

    try
    {
        if (ListBox1.Items.Count > 0)
        {
            for (int i = 0; i <= ListBox1.Items.Count; i++)
            {
                if (ListBox1.Items[i].Selected == true)
                {
                    lblempid.Text = Convert.ToString(ListBox1.Items[i].Text.Substring(0, 8));
                    lblempname.Text = Convert.ToString(ListBox1.Items[i].Text.Substring(9));
                    DataSet5TableAdapters.sp_GetallpayperiodTableAdapter TA = new DataSet5TableAdapters.sp_GetallpayperiodTableAdapter();
                    DataSet5.sp_GetallpayperiodDataTable DS = TA.GetData();
                    if (DS.Rows.Count > 0)
                    {
                        fromdate = Convert.ToString(DS.Rows[DS.Rows.Count - 1]["fldstartdate"]);
                        todate = Convert.ToString(DS.Rows[DS.Rows.Count - 1]["fldtodate"]);
                        status = Convert.ToString(DS.Rows[DS.Rows.Count - 1]["fldstatus"]);
                        if (status == "OPEN")
                        {
                            lblfromdate.Text = Convert.ToString(Convert.ToDateTime(fromdate).ToShortDateString());
                            lbltodate.Text = Convert.ToString(Convert.ToDateTime(todate).ToShortDateString());
                        }
                    } 

                }
            }
        }

    }
    catch (Exception e1)
    {
        ScriptManager.RegisterStartupScript(this, this.GetType(), "onload", "<script language='javascript'>alert('" + e1.Message + "');</script>", false);
    }

设计代码:

       <%@ Register Assembly="MetaBuilders.WebControls" Namespace="MetaBuilders.WebControls"
TagPrefix="mb" %>

        <mb:CheckedListBox ID="ListBox1" runat="server" CssClass="textbox" Width="250px"
                                                                            Height="515px" AutoPostBack="True" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged">
                                                                        </mb:CheckedListBox>

1 个答案:

答案 0 :(得分:0)

请检查您的aspx代码中的自动回复是否为真: 例如:

<asp:DropDownList ID="ddlForecastOption" runat="server" 
      onselectedindexchanged="ddlForecastOption_SelectedIndexChanged" 
      AutoPostBack="true">