2012-04-25 64 views
0

上午使用元建設者檢查列表框和他們選定的索引改變工作正常local.but不工作在服務器端。請幫我解決這個錯誤。我的部分代碼是在這裏..metabuilder檢查列表框選擇索引更改不起作用的服務器

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> 

回答

0

請檢查是否自動回發是你的aspx代碼真: 例子:

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