我在我的 .aspx 页面中使用 2 个复选框列表控件,即 chklstearnings、chklstdeductions,并使用数据集将数据绑定到复选框列表。现在,当我尝试获取所选项目时,我无法这样做。
这是我的数据绑定代码:
page_load
{
MySqlConnection con= new MySqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("connectionString"));
MySqlCommand com=con.CreateCommand();
com.CommandText="select earningordeductiondescription,earningordeductioncode from tblearninganddeduction where earningordeductioncode between 1000 and 1999";
com.CommandType=CommandType.Text;
DataSet ds=new DataSet();
MySqlDataAdapter da=new MySqlDataAdapter();
da.SelectCommand=com;
da.Fill(ds,"earnings");
chklstEarnings.DataSource=ds.Tables["earnings"];
chklstEarnings.DataTextField = "earningordeductiondescription";
chklstEarnings.DataValueField="earningordeductioncode";
chklstEarnings.DataBind();
MySqlCommand com1 = con.CreateCommand();
com1.CommandText = "select earningordeductiondescription,earningordeductioncode from tblearninganddeduction where earningordeductioncode between 2000 and 2999";
com1.CommandType = CommandType.Text;
da.SelectCommand = com1;
da.Fill(ds, "deductions");
chklstdeductions.DataSource = ds.Tables["deductions"];
chklstdeductions.DataTextField = "earningordeductiondescription";
chklstdeductions.DataValueField = "earningordeductioncode";
chklstdeductions.DataBind();
}
所选项目的按钮单击代码:
protected void btnsubmit_Click(object sender, EventArgs e)
{
foreach (ListItem ear in chklstEarnings.Items)
{
if (ear.Selected)
{
//save the earning prefarences
}
}
foreach (ListItem ded in chklstdeductions.Items)
{
if (ded.Selected)
{
//save the deduction prefarences
}
}
}
现在我的问题是我在 ded 和 ear 中获得了项目的名称,但是选择的属性是所有显示错误的方式,不考虑选择
感谢广告