【发布时间】:2016-08-17 18:37:34
【问题描述】:
我需要根据单元格是否包含字符串“是”或“否”来格式化网格视图中的 2 个整列。我到处找东西,试图找到完成我想做的事情,但找不到任何基于字符串的东西,只有 int 值。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView gv = (GridView)e.Row.FindControl("GridView2");
var ds = new SqlDataSource();
ds.ConnectionString = ConfigurationManager.ConnectionStrings["HUTDMSConnectionString"].ConnectionString;
ds.SelectCommand = "SELECT * FROM textBooks WHERE CourseID = '" + GridView1.DataKeys[e.Row.RowIndex].Value + "' ORDER BY BookTitle";
gv.DataSource = ds;
gv.DataBind();
}
}
我知道条件格式在gridview_rowdatabound 中
事件。
到目前为止我所拥有的:
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.DataRow && ((e.Row.RowState & DataControlRowState.Edit) == 0))
{
var valueFetched = ((TableCell)(e.Row.Cells[3].FindControl("no"))).Text;
if (valueFetched == "no")
{
foreach (var cell in e.Row.Cells)
((TableCell)cell).BackColor = Color.Red;
}
}
}
【问题讨论】: