我用DataGrid邦定数据库中我要显示的列,其中有一列的值只有1,2,3,4中的一个,分别代表不同的含义,我的问题是让DataGrid显示的时候,如果那一列的值是1,显示汽车,如果是2,显示火车,以此类推,请问给位应该怎么做?

解决方案 »

  1.   

    colums[1] = "汽车那一项"
    是不是这样!
      

  2.   

    在DataGrid_ItemDataBound事件里string i = e.Item.Cells[1].Text;
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    if (i.Contains("1") == true)
    {
        e.Item.Cells[1].Text = i.Replace("1", "汽车");
    }
    if (i.Contains("2") == true)
    {
        e.Item.Cells[1].Text = i.Replace("2", "火车");
    }
    }
      

  3.   

    改一下 应该是
    在DataGrid_ItemDataBound事件里string i = e.Item.Cells[1].Text;
     if(e.Item.ItemType == DataControlCellType.DataCell)
    {
    if (i.Contains("1") == true)
    {
        e.Item.Cells[1].Text = i.Replace("1", "汽车");
    }
    if (i.Contains("2") == true)
    {
        e.Item.Cells[1].Text = i.Replace("2", "火车");
    }
    }