내 .aspx 페이지에서 두 개의 체크 박스 컨트롤, 즉 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과 귀에 항목의 이름을 얻고있다 선택한 부동산은 선택에 대한 거짓된 태도를 나타내는 모든 방법입니다.
감사의 말
당신은 aspx 마크 업을 게시 할 수 있습니까? 가능한 이유 EnableViewState가 페이지에서 false 일 수 있습니다. –