日期:2014-05-18  浏览次数:20868 次

改变datagrid的输出显示``
````````我用datagrid绑定数据后``有一条记录在数据库是用0,1
如果数据库是0则显示     '病假 '   1显示 '事假 '
              怎样做啊````

------解决方案--------------------
在GridView的RowDataBind事件中写
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if(e.Row.Cells[0].Text== "0 ") //假设第1列是你要改变的
{
e.Row.Cells[0].Text= "病假 ";
}
else
{
e.Row.Cells[0].Text= "事假 ";
}
}
}
这是一种写死的方法
其实可以在前台绑定的时候转换
------解决方案--------------------
<%# DataBinder.Eval(Container.DataItem, "Status ").ToString().ToLower() == "true "? "ddd ": " <font color=red> kaka </font> " %>
------解决方案--------------------
RowDataBind是是gridview的帮定数据的一个事件,你绑定的时候读0或1,再修改相应的单元格的值为事假 病假
代码就如上

chuqiang0910() ( ) 信誉:100 2007-8-22 14:58:33 得分: 0



在GridView的RowDataBind事件中写
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if(e.Row.Cells[0].Text== "0 ") //假设第1列是你要改变的
{
e.Row.Cells[0].Text= "病假 ";
}
else
{
e.Row.Cells[0].Text= "事假 ";
}
}
}
这是一种写死的方法
其实可以在前台绑定的时候转换




------解决方案--------------------
<%# DataBinder.Eval(Container.DataItem, "Status ").ToString()== "0 "? "病假 ": " <font color=red> 事假 </font> " %>


---------------------------------------------------

这个
------解决方案--------------------
在cs页面里面写一个public string GetValueName(string value)
{
if(string.isEmptyOrNull(value))
return "未知 ";
switch(value)
{
case "1 ":
return "病假 ";
case "2 ":
return "事件 ";
default:
return "未知假 ";
}

}


<%# GetValueName(Eval( "Value "))%>

这样最好