//*****你在前在模版列定义一个CheckBoxList控件//****在RowDataBoud事件进行处理哈CheckBoxList ckbList=(CheckBoxList)e.RowItem.FindControl("ckbList");//****定一个函数邦寂静数据处理
CheckBoxListBind(ref ckBList,false);//****默认选择你需的项哈
for(int i=9;i<ckbList.Items.Count;i++)
{
   string[] DBParamtes=strTemp.split(',')
   foreach(string strTempA in DBParamtes)
   {
      if(ckbList.Items[i].value==srrTempA)ckbList.Items[i].checked=true;
   }
}

解决方案 »

  1.   

    但是我怎么 知道我是知道我要棒定的字符传呢,这个是从数据库中获取,并且checkboxlist
    的选项名是从数据库去的
    比如
    [] last 50
    [] last 100
    [] last 150 
    这个是从数据字典表中棒定的
    但是
    对应的每一个合同,他对应的有个字符传,(如)1,3,
    那么选中第一项和第二项
      

  2.   

    高定,public partial class Customer_frmCustomerViewReports : System.Web.UI.Page
    {
        private DataSet ds;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                getContract();
            }
        }
        public void getContract()
        { 
            string strconnt = "server=server01;database=cisco;uid=sa;pwd=sql";
            SqlConnection con = new SqlConnection(strconnt);
            con.Open();
            SqlCommand cmd = new SqlCommand("CIS_GetAllReportsByCustomer", con);
           
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@Cust_ID", "cu000002");
            SqlDataAdapter da = new SqlDataAdapter(cmd);
             ds = new DataSet();
            da.Fill(ds);
            Gridview1.DataSource = ds;
            Gridview1.DataBind();
            ////string str = ds.Tables[0].Rows[0]["Report_No"].ToString();
            //////CheckBoxList list = Gridview1.FindControl("chkReports") as CheckBoxList;
          
            //////string[] strarr = str.Split(',');
            //////for (int i = 0; i < list.Items.Count; i++)
            //////{
            //////    for (int j = 0; j < strarr.Length; j++)
            //////    {
            //////        if (list.Items[i].Value == strarr[j])
            //////        {
            //////            list.Items[i].Selected = true;
            //////        }
            //////    }
            //////}
                }
        public DataTable bindData()
        {
            return new BLCommon().BLGetResportReference().Table;
        }    protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType ==DataControlRowType.DataRow)
            {
                CheckBoxList list = new CheckBoxList();
                list = e.Row.FindControl("chkReports") as CheckBoxList;
                Label lbl = new Label();
                lbl = e.Row.FindControl("lblID") as Label;            string str = lbl.Text; //ds.Tables[0].Rows[0]["Report_No"].ToString();
                string[] strarr = str.Split(',');
                for (int i = 0; i < list.Items.Count; i++)
                {
                    for (int j = 0; j < strarr.Length; j++)
                    {
                        if (list.Items[i].Value == strarr[j])
                        {
                            list.Items[i].Selected = true;
                        }
                    }
                }
            }
        }
    }