CheckBoxList绑定数据库问题
private void Page_Load(object sender, System.EventArgs e)
{
SqlConnection conn=new SqlConnection( "database=outlook;server=.;uid=sa;pwd=sa ");
SqlDataAdapter adp=new SqlDataAdapter( "select U_ID,U_RName from kojin ",conn);
DataSet ds=new DataSet();
adp.Fill(ds, "z ");
DataTable Dt = ds.Tables[ "z "];
this.CheckBoxList1.DataSource=Dt;
this.CheckBoxList1.DataTextField = "U_RName ";
this.CheckBoxList1.DataValueField = "U_ID ";
this.CheckBoxList1.DataBind();
}
private void Button1_Click(object sender, System.EventArgs e)
{
string Temp = " ";
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
Temp += CheckBoxList1.Items[i].Text.ToString();
}
}
Label1.Text = Temp;
}
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
点button获取不到值... 帮看下~~
button 控制 AutoPostBack无关吧
------解决方案--------------------在PageLoad里加上这个就不会丢失你所失去的值了
if(!Page.IspostBack)
{
............
}