方法一:在把数据绑定到DataSet后,更改里面的数据,例如:
SqlDataAdapter myCmd=new SqlDataAdapter(strSql,myConn);
DataSet ds=new DataSet();
myCmd.Fill(ds,"操作员");
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
if(ds.Tables[0].Rows[i]["Oper_state"].ToString()=="1")
ds.Tables[0].Rows[i]["Oper_state"]="有效";
else if(ds.Tables[0].Rows[i]["Oper_state"].ToString()=="0")
ds.Tables[0].Rows[i]["Oper_state"]="冻结";
}
MyDataGrid.DataSource=ds.Tables["操作员"].DefaultView;
MyDataGrid.DataBind();
方法二:通过写一个函数,把绑定到DataGrid某一列的数据转化成要显示字符串,例如:
SqlDataAdapter myCmd=new SqlDataAdapter(strSql,myConn);
DataSet ds=new DataSet();
myCmd.Fill(ds,"操作员");
MyDataGrid.DataSource=ds.Tables["操作员"].DefaultView;
MyDataGrid.DataBind();
在DataGrid摸版列里这样绑定数据:
<%# TurnToStatus(DataBinder.Eval(Container.DataItem,"Oper_state").ToString()) %>
SqlDataAdapter myCmd=new SqlDataAdapter(strSql,myConn);
DataSet ds=new DataSet();
myCmd.Fill(ds,"操作员");
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
if(ds.Tables[0].Rows[i]["Oper_state"].ToString()=="1")
ds.Tables[0].Rows[i]["Oper_state"]="有效";
else if(ds.Tables[0].Rows[i]["Oper_state"].ToString()=="0")
ds.Tables[0].Rows[i]["Oper_state"]="冻结";
}
MyDataGrid.DataSource=ds.Tables["操作员"].DefaultView;
MyDataGrid.DataBind();
方法二:通过写一个函数,把绑定到DataGrid某一列的数据转化成要显示字符串,例如:
SqlDataAdapter myCmd=new SqlDataAdapter(strSql,myConn);
DataSet ds=new DataSet();
myCmd.Fill(ds,"操作员");
MyDataGrid.DataSource=ds.Tables["操作员"].DefaultView;
MyDataGrid.DataBind();
在DataGrid摸版列里这样绑定数据:
<%# TurnToStatus(DataBinder.Eval(Container.DataItem,"Oper_state").ToString()) %>
select sftj = case sftj when 1 then "未提交" when 0 then "提交" end,* from 数据表
if (e.Item.ItemIndex >= 0)
{
if (e.Item.Cells[3].Text == "0")//检查第四列字段
{
e.Item.Cells[3].Text = "提交";//改变显示内容
}
else
{
e.Item.Cells[3].Text = "未提交";
}
}
protected void GetCustomValue(string strValue)
{
return (strValue=="0")?"提交":"未提交"}