举例说明:厂商表A: 
 csid   csname 
 编码     名称 证照表B 
 zzid   zzname 
 编码      名称 厂商证照表C(因为一个厂商可能对应多个证照,所以单建一个表) 
  csid    zzid 
 厂商编码 证照编码 现在作了一个显示单个厂商的页面,在这个页面显示出了厂商的基本信息(来自A表)、全部证照信息(来自B表,而且用CheckBoxList复选框来显示全部证照),现在问题是如何根据这个厂商证照表C的查询结果,将拥有的证照复选框Selected=True,没有的仍为False,如何实现?不知道说清楚了没

解决方案 »

  1.   

    先将数据全查询出来帮定在checkboxlist上,
    然后再选数据,对照已经帮定的checkboxlist的item,value相等的checked=true;
      

  2.   

    参考一下这个,就明白了
    Private Sub RadioButtonList1_SelectedIndexChanged(sender As Object, e As System.EventArgs)
       Dim chk As ListItem
       For Each chk In  Me.CheckBoxList1.Items
          chk.Selected = False
       Next chk
       Dim SecondTypeID As String = ""
       Dim con As SqlConnection = DB.CreateCon()
       con.Open()
       Dim cmd As New SqlCommand("select SecondTypeID from  LabSedType  where UserID='" + Me.RadioButtonList1.SelectedValue + "'", con)
       Dim sdr As SqlDataReader = cmd.ExecuteReader()
       While sdr.Read()
          SecondTypeID = sdr.GetInt32(0).ToString()
          Dim chk As ListItem
          For Each chk In  Me.CheckBoxList1.Items
             
             If chk.Value = SecondTypeID Then
                chk.Selected = True
             End If
          Next chk
       End While 
       sdr.Close()
       con.Close()
    End Sub
      

  3.   

    SqlHelper db=new SqlHelper();
    protected void Page_Load(object sender, EventArgs e)
        {
            CheckBoxList1.DataSource = db.getds("select id,name from 表B");
            CheckBoxList1.DataTextField = "name";
            CheckBoxList1.DataValueField = "id";
            CheckBoxList1.DataBind();        DataSet ds = db.getds("select id,name from 表C");
            for (int i = 0; i < CheckBoxList1.Items.Count; i++)
            {
                if (CheckBoxList1.Items[i].Text == ds.Tables[0].Rows[i]["name"].ToString())
                {
                    CheckBoxList1.Items[i].Selected = true;
                }
            }    }
      

  4.   

       不知道我的理解是否正确, 我想你用查询count 函数 数c表 zzid   有就不等于0,没有就等于0,然后在判断 是否选择 
    checkbox