在DataGrid(已绑定Oracle数据库)中,如何通过一个字段的结果来显示其他信息?
  如:LTIME字段的结果有三种情况:1;2;3,在DataGrid中分别显示的结果是:1:00-8:00;8:00-17:00;17:00-1:00。
  在Asp.net(C#)里如何写代码,不要通过数据库查询语句判断来显示结果。

解决方案 »

  1.   

    public string getLtime(string i)
    {
       switch(i)
       {
         case "1":
            return "1:00-8:00";
         .......
       }
    }private void DataGrid1_ItemDataBound(..)
    {
      if(e.Item.ItemIndex>-1)
          e.Item.Cells[0].Text = getLtime(e.Item.Cells[0].Text);
    }
      

  2.   

    试试:
    foreach(DataGridItem Item in DataGrid1.Items)
    {
    if(Item.Cells[9].Text=="1")
    {
    Item.Cells[9].Text="1:00-8:00";
    }
    else if(Item.Cells[9].Text=="2")
    {
    Item.Cells[9].Text="8:00-17:00";
    }
    else if(Item.Cells[9].Text=="3")
    {
    Item.Cells[9].Text="17:00-1:00";
    }
    }
      

  3.   

    或者public string getLtime(string i)
    然后用<%#.....%>直接绑定
      

  4.   

    假设那个LTIME字段在这个DataGrid中的第I列,就可以这样判断:
    foreach(DataGridItem item in DataGrid.Items)
    {
        if(item.Cells[I].Text == "1")
        {
           item.Cells[I].Text = "1:00-8:00";
        }
        else ..........................
    }
      

  5.   

    非常感谢 Eddie005(╬) 暴赱 (╬) ,他的方法很好,我只试了他的方法