我正在使用元生成器检查列表框,并且他们选择的索引更改为在本地工作正常。但在服务器端不工作。请帮我解决这个错误。我的部分代码在这里..
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>