这个问题可以这样做:
1)建立数据库视图或存储过程,将O,1,2改成0--完成,1--进行中,2--未开工,这个很容易,而且最好,建议你使用这种方式,而且这种方式基本上不用该程序代码,只要把原来的表名改成现在的视图名就可以了
2)在Grid的DataItemCreate或ItemDateBind事件(大概是这个名)中填写代码,判断该列的值,然后设置,这种方式下你还可以设置不同的背景色,如果完成的一行设为红色,进行中的设为绿色,没开工的设为黄色

解决方案 »

  1.   

    check the data value in ItemDataBound event handler, change the text in the corresponding cell
      

  2.   

    TO  nkdzc() , saucer(思归):
        其实你所说的第一个方法使用存储过程我也想到了,不过我们经理不让我用,他说是便于以后系统的移值,没办法,对于你所说的ItemDataBound事件,我还不是很会用,要怎么在这个事件中取到模板中的控件,又如何设置它的文本,(因为模板中Label控件的ID都是服务器分配的),还有如何取出当前值的itend值,能不能附上一段代码好吗?对了,如果不介意留下你们的MSN可以交个朋友好不..再次非常感谢你们...拜托了.
      

  3.   

    我现在做的项目中很多类似的问题!
    我们一般把这些对应表单独存在一张表中叫做代码表。在需要用到的像上述的对应关系,存入主表中的是它的值0,1,2,其该值和对应值中文意思再代码表中。
    当需要用DataGrid显示时候,不需要用Template,直接在CS中用方法转化过来
    或者在DataSet取得值时,如查询条件:"select name,DMToDMNR(xb) as xb
    from userinfo",其中DMToDMNR是在SQL Server 自定义的函数,很简单的函数从代码表中输入它的值,得到它的对应值就行了
    然后DataGrid中,字段帮定还是一样,name,xb等
      

  4.   

    楼上的大哥,其实如果在SQL Server中解决问题是会简单很多,不过,现在问题是我们经理不准我使用存储过程之类的东西,而且你所说的表我也不能建立,都是由经理来建立的,所以这可能比较难实现,只能在页面上进行判断赋值..有没有办法
      

  5.   

    select CASE isend
             WHEN 1 THEN '进行中'
             WHEN 2 THEN '未开工'
             ELSE '完成'
          END AS send_status
      

  6.   

    To qiushuiwuhen(秋水无恨):
        这个语句在SQL Server中可以使用,不过在其它数据库服务器中可以使用吗?有没有可以在页面实现的方法呢?
      

  7.   

    1.datagrid.aspx:
    <%@ Page Inherits="MyDataGridPage" src="Datagrid.cs" %>
    <html>
    <body>
      <h3><font face="Verdana">Curstomize Datagrid</font></h3>
    <form runat="server">
      <ASP:DataGrid id="MyDataGrid" runat="server">
       <Columns>
    <asp:TemplateColumn>
     <HeaderTemplate><b>Name</b></HeaderTemplate>
              <ItemTemplate>
                <asp:Label runat="server"/>
              </ItemTemplate>
             </asp:TemplateColumn>
        </Columns>
      </asp:DataGrid>
    <asp:button id="Button1" runat="Server" Text="click" />
    </form>
    </body>
    </html>
    </html>2. datagrid.cs:
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.SqlClient;public class MyDataGridPage : Page 
    {
      protected DataGrid MyDataGrid;
      protected override void OnLoad(EventArgs e)
      {
         if (!IsPostBack)
         {
      string sConn = "server=localhost;database=pubs;uid=sa;pwd=;";
            SqlDataAdapter myDA = new SqlDataAdapter("select * from authors", sConn);        DataSet ds = new DataSet();
            myDA.Fill(ds, "authors"); DataView dv = ds.Tables["authors"].DefaultView;
             MyDataGrid.AutoGenerateColumns = false;
    MyDataGrid.ItemDataBound += new DataGridItemEventHandler(OnItemDataBound);        MyDataGrid.DataSource= dv;
            MyDataGrid.DataBind();
          }
      }   string[] sTaskStatus = {"完成","进行中","未开工"};   protected void OnItemDataBound(object sender, DataGridItemEventArgs e)
       {
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
           {

    string sID = DataBinder.Eval(e.Item.DataItem, "au_id" ).ToString();
    int n = Convert.ToInt32(sID.Substring(0,3)); ControlCollection cc = e.Item.Cells[0].Controls;
    if (cc.Count > 0)
    {
    for (int i=0; i < cc.Count; i++)
    {
    if (cc[i] != null && cc[i] is Label)
    {
       ((Label)cc[i]).Text = (sTaskStatus[n%3]) + ":" + sID;
    }
    }
    }
    }
        }
    }
      

  8.   

    To saucer(思归) :
         真的很感谢你,照你的方法的确可以,只是我还有两处不明,还望解答:
    1:MyDataGrid.ItemDataBound += new DataGridItemEventHandler(OnItemDataBound);
     这一句是什么意思,有什么用处呢?DataGrid不是有ItemDataBound事件吗?为什么还要加一个呢>2. if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
      这一句是什么函意啊?3.假如同一个模板内有两个不同的控件都要赋值怎么办呢??>谢谢啦!!!!
      

  9.   

    1. it binds the event handler programmatically, don't you say "我们经理要求所有的代码都要写在类文件中"?? if you already have 
    <asp:datagrid OnItemDataBound=".." ...>
    then just remove that line2. DataGrid is displayed as a HTML table, it could have Header, Footer, Pager, Item, AlternatingItem,... normally, ListItemType.Item means row 1,3,5,...and ListItemType.AlternatingItem means row 2,4,6,....the if statement just checks if you are dealing with the table body3. go through
    e.Item.Cells[0],e.Item.Cells[1],...,e.Item.Cells[e.Item.Cells.Count-1]