日期:2014-05-20 浏览次数:20637 次
void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
  {
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
      // Display the company name in italics.
      e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";
    }
  }
------解决方案--------------------
datalist控件的,可以作为参考
protected void dlCcList_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (Request["mailerId"] == null)
                return;
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                string mailerId = Request["mailerId"];
                Ecommerce.BLL.Ecommerce_Cclist_Mailer cclist_MailerBll = new Ecommerce.BLL.Ecommerce_Cclist_Mailer();
                string dataKey = dlCcList.DataKeys[e.Item.ItemIndex].ToString();
                List<Ecommerce.Model.Ecommerce_Cclist_Mailer> cclist_MailerList
                            = cclist_MailerBll.GetModelList("mailerid = " + mailerId + " and cclistid=" + dataKey);
                if (cclist_MailerList.Count > 0)
                {
                    ((CheckBox)e.Item.FindControl("CheckBox1")).Checked = true;
                }
            }
        }
------解决方案--------------------
有默认属性的 你只要checkbox 的 value里面字就可以设置
------解决方案--------------------
DataSet ds=new DataSet();
        using(SqlConnection conn=new SqlConnection("server=(local);database=你的数据库;integrated security=sspi"))
        {
            SqlDataAdapter da=new SqlDataAdapter("select * from table1",conn);
            da.Fill(ds,"table1");
            DataColumn filed3 = new DataColumn("isExist", typeof(System.Boolean));
            ds.Tables["table1"].Columns.Add(filed3);
            for (int i = 0; i < ds.Tables["table1"].Rows.Count; i++)
            {
                SqlCommand cmd=new SqlCommand(string.Format("select * from table2 where filed1='{0}'",ds.Tables["table1"].Rows[i][0]),conn);
                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleRow);
                if (dr.Read())
                {
                    ds.Tables["table1"].Rows[i][2] = true;
                }
                else
                {
                    ds.Tables["table1"].Rows[i][2] = false;
                }
            }
        }