在gridView绑定数据的时候,根据所绑定的数据来确定行的颜色,这个功能要怎么实现?
14 个解决方案
#1
在rowbound事件中做.
e.Row.BackColor
e.Row.BackColor
#2
可以在绑定时执行一个JS方法来确定行的颜色
#3
RowDataBound事件里判断
#4
没有,是我想复杂了,我原本想的是怎么获取这行所绑定的数据,怎么从事件中sender或者e来获取数据,发完贴后一想,直接找到那个GridView中要进行判断的那个控件,从哪个控件中取值就好了。刚刚是脑子短路了
#5
for(int i=0;i<Gridview1.rows.count;i++)
{
if(Gridview1.Rows[i].Cells[0].ToString() == "mm")//等于mm时的判断
Gridview1.Row.BackColor=System.Drawing.Color.Red;//行的颜色
}
{
if(Gridview1.Rows[i].Cells[0].ToString() == "mm")//等于mm时的判断
Gridview1.Row.BackColor=System.Drawing.Color.Red;//行的颜色
}
#6
前台代码:
后台代码:
hField 为什么会报空值那?
<asp:TemplateField HeaderText="是否到期" SortExpression="IsScrap">
<ItemTemplate>
<%# Encode(Eval("isOverdue").ToString())%>
<asp:HiddenField ID="IsOverdue" runat="server" Value='<%# Eval("isOverdue")%>' />
</ItemTemplate>
</asp:TemplateField>
后台代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
HiddenField hField = (HiddenField)e.Row.FindControl("IsOverdue");
if (hField.Value.Trim() == "1")
{
e.Row.BackColor = Color.Red;
}
}
hField 为什么会报空值那?
#7
哦,没判断表头~
#8
RowDataBound事件里判断
好像是:e.Row.BackColor
好像是:e.Row.BackColor
#9
试试:
设置Label1为不可见,所在列为第2列(根据实际修改)
设置Label1为不可见,所在列为第2列(根据实际修改)
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
}
if (e.Row.RowIndex >= 0)
{
Label lab= (Label)(e.Row.Cells[1].FindControl("Label1"));
if (lab.text.ToString()=="1")
{
e.Row.BackColor = System.Drawing.Color.Red;
}
}
}
#10
Google: GridView72般绝技
#12
RowDataBind事件
if (e.Row.RowType == DataControlRowType.DataRow)
{
if(e.row.cells[]== )
{e.row.backcolor= ;}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
if(e.row.cells[]== )
{e.row.backcolor= ;}
}
#13
<%# Eval("字段").ToString().Equals("")?
"<font clor=\"red\">"+Eval("title")+"</font>":Eval("title")%>
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridViewRow gvr = e.Row;
gvr.BackColor = System.Drawing.Color.Red;
}
"<font clor=\"red\">"+Eval("title")+"</font>":Eval("title")%>
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridViewRow gvr = e.Row;
gvr.BackColor = System.Drawing.Color.Red;
}
#14
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{ColorConverter cc = new ColorConverter();
Label labValue = (Label)e.Row.FindControl("lab");
e.Row.BackColor =(Color)cc.ConvertFromString(labValue.Text);
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{ColorConverter cc = new ColorConverter();
Label labValue = (Label)e.Row.FindControl("lab");
e.Row.BackColor =(Color)cc.ConvertFromString(labValue.Text);
}
}
#1
在rowbound事件中做.
e.Row.BackColor
e.Row.BackColor
#2
可以在绑定时执行一个JS方法来确定行的颜色
#3
RowDataBound事件里判断
#4
没有,是我想复杂了,我原本想的是怎么获取这行所绑定的数据,怎么从事件中sender或者e来获取数据,发完贴后一想,直接找到那个GridView中要进行判断的那个控件,从哪个控件中取值就好了。刚刚是脑子短路了
#5
for(int i=0;i<Gridview1.rows.count;i++)
{
if(Gridview1.Rows[i].Cells[0].ToString() == "mm")//等于mm时的判断
Gridview1.Row.BackColor=System.Drawing.Color.Red;//行的颜色
}
{
if(Gridview1.Rows[i].Cells[0].ToString() == "mm")//等于mm时的判断
Gridview1.Row.BackColor=System.Drawing.Color.Red;//行的颜色
}
#6
前台代码:
后台代码:
hField 为什么会报空值那?
<asp:TemplateField HeaderText="是否到期" SortExpression="IsScrap">
<ItemTemplate>
<%# Encode(Eval("isOverdue").ToString())%>
<asp:HiddenField ID="IsOverdue" runat="server" Value='<%# Eval("isOverdue")%>' />
</ItemTemplate>
</asp:TemplateField>
后台代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
HiddenField hField = (HiddenField)e.Row.FindControl("IsOverdue");
if (hField.Value.Trim() == "1")
{
e.Row.BackColor = Color.Red;
}
}
hField 为什么会报空值那?
#7
哦,没判断表头~
#8
RowDataBound事件里判断
好像是:e.Row.BackColor
好像是:e.Row.BackColor
#9
试试:
设置Label1为不可见,所在列为第2列(根据实际修改)
设置Label1为不可见,所在列为第2列(根据实际修改)
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
}
if (e.Row.RowIndex >= 0)
{
Label lab= (Label)(e.Row.Cells[1].FindControl("Label1"));
if (lab.text.ToString()=="1")
{
e.Row.BackColor = System.Drawing.Color.Red;
}
}
}
#10
Google: GridView72般绝技
#11
#12
RowDataBind事件
if (e.Row.RowType == DataControlRowType.DataRow)
{
if(e.row.cells[]== )
{e.row.backcolor= ;}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
if(e.row.cells[]== )
{e.row.backcolor= ;}
}
#13
<%# Eval("字段").ToString().Equals("")?
"<font clor=\"red\">"+Eval("title")+"</font>":Eval("title")%>
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridViewRow gvr = e.Row;
gvr.BackColor = System.Drawing.Color.Red;
}
"<font clor=\"red\">"+Eval("title")+"</font>":Eval("title")%>
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridViewRow gvr = e.Row;
gvr.BackColor = System.Drawing.Color.Red;
}
#14
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{ColorConverter cc = new ColorConverter();
Label labValue = (Label)e.Row.FindControl("lab");
e.Row.BackColor =(Color)cc.ConvertFromString(labValue.Text);
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{ColorConverter cc = new ColorConverter();
Label labValue = (Label)e.Row.FindControl("lab");
e.Row.BackColor =(Color)cc.ConvertFromString(labValue.Text);
}
}