如何根据条件更改Gridview行颜色。 [英] How to change Gridview Row Color Based on Condition.
问题描述
大家可以帮帮我吗?
我想根据价值改变Gridview的行颜色。
Hi can anyone help me out?
I wanna change the Gridview row color Based on Value.
推荐答案
Hi
在服务器端网格数据绑定中尝试此操作
Hi Try this in server side grid databound
protected void gvDevice_RowDataBound(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowType == DataControlRowType.DataRow)) {
Image imgStatuss = e.Row.FindControl("imgStatus");
string status = DataBinder.Eval(e.Row.DataItem, "IPAddress");
try {
Ping ping = new Ping();
PingReply pingreply = ping.Send(status);
string reply = pingreply.Status;
if ((reply == 0)) {
e.Row.BackColor = Drawing.Color.Yellow;
} else {
e.Row.BackColor = Drawing.Color.Blue;
}
} catch (Exception ex) {
}
}
}
在上面的代码我将获得IP地址格式的网格视图和我ping ip地址,我可以ping该行变为黄色,如果没有ping变为蓝色。
i将从字符串状态= DataBinder.Eval(e.Row.DataItem,IPAddress)获取IP地址;
i在gridview中有ip地址列并使用e.Row.DataItem获取该ip并且处于状态,然后我将在状态字符串中ping ip地址,如果它回复(成功ping)0然后行颜色变为黄色,我没有得到0然后换成蓝色
你的例外从网格视图获取值并检查值并为行指定颜色
问候
Aravind
in above code i will get ip address form gridview and i ping ip address,i can ping that row change to yellow color,if not ping change to blue color.
i will get ip address from string status = DataBinder.Eval(e.Row.DataItem, "IPAddress");
i have ip address column in gridview and get that ip using e.Row.DataItem and assing in status,then i will ping ip address in status string,if it reply(successfully ping) 0 then row color change to yellow,i not get 0 then change to blue color
in ur excepetation get value form grid view and check that values and assign color for row
Regards
Aravind
protected void gvrequests_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string strIsEnable = e.Row.Cells[8].Text;
if (strIsEnable == "False")
{ e.Row.BackColor = System.Drawing.Color.LightBlue; }
}
}
这篇关于如何根据条件更改Gridview行颜色。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!