首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

gridview后盾控制某列的样式

2012-08-15 
gridview后台控制某列的样式如题,想在后台控制某列的样式,比如当那列含有某个关键字时,显示为红色,是在 pr

gridview后台控制某列的样式
如题,想在后台控制某列的样式,比如当那列含有某个关键字时,显示为红色,是在 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

}
中写的吧,能给点提示吗?先谢谢了

[解决办法]
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow) {
if (e.Row.Cells[0].Text.Contains("关键字")) e.Row.Attributes.Add("style", "color:red");
}
}
[解决办法]
你这种写法不好控制,你最好设置个控件



<asp:TemplateField><ItemTemplate><tr style='HEIGHT: 10px;<asp:Literal id=xx runat=server/>'>

if (e.Row.RowType == DataControlRowType.DataRow) {
if (e.Row.Cells[0].Text.Contains("关键字"))
{
 Literal xx = e.Row.FindControl("xx") as Literal;
xx.Text = "color:red";
}
}
[解决办法]
楼主可以用datalist,不用再添加控件!我以前做过关键字查询的,关键字返回红色,你看看下面的例子:

C# code
DataTable dt =返回的表for(int i = 0 ;i<dt.Rows.count;i++){循环表各行 dt.Rows[i]["列名"] = (dt.Rows[i]["列名"] + "").Replace(Tkey.Text.ToString(), "<FONT color=#ff0000>" + Tkey.Text.ToString() + "</FONT>");}datalist1.DataSource=dt;datalist1.DataBind(); 

热点排行