在.aspx页面代码如下:
<asp:GridView ID="dgrFSGRItem" runat="server" Width="100%" AutoGenerateColumns="False">
                  <Columns>
                  <asp:BoundField DataField="Plant" HeaderText="Plant" />
                  <asp:BoundField DataField="POSTTM" HeaderText="GR Date" />
                  ..........................................
 
在.aspx.cs页面想写一个if语句,把Plant作为一个判定条件。应该怎么写呢?
谢谢!!

解决方案 »

  1.   

    如果是简单的对比,可以在SQL语句里面,用case when then end来实现。
      

  2.   

    用在哪的...
            for (int i = 0; i < this.GridView1.Rows.Count; i++)
            {
                string str = this.GridView1.Rows[i].Cells[0].Text;//第i行第0+1列的值
                Response.Write(str);
            }
      

  3.   

    楼主要 研究 一下 gridview rowdatabound 函数里面你获取值后 想怎么处理就怎么处理     别说一个判断  你写10个逻辑判断 也行不要把GridView看的很死板 只会单独绑定一个数据
      

  4.   


    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
            if (e.Row.RowIndex >= 0)
            {
                string plant = e.Row.Cells[1].Text.ToString();//PLANT所在列
                
                if (plant=="") //判断
                  {
                    //.....
                }
            }
    }
      

  5.   

    用用gridview的rowdatabound  另一种境界
      

  6.   

    试一下三元运算   (expr1=="0") ? (expr2) : (expr3),
      

  7.   

    楼主,你可以运用一下面向对象的方式来传对象,而不是datasource=datatable的形式,可以传一个ArrayList对象,里边包括你的实体类 ,实体类里包括get,set,在get里进行判断,我觉得这个是最正规的办法,一切可以拿到gridview之外来做
      

  8.   

    RowDataBound是GridView的属性吗?怎么使用RowDataBound呢?
      

  9.   

    RowDataBound是GridView的方法!!
      

  10.   

    RowDataBound是GridView的事件,右键属性   事件   双击RowDataBound事件就可以进去了。。然后再里面写上面的那些代码
      

  11.   

    我觉得还是把BoundField  换成 TemplateField  比较好
    这样绑定的时候就能添加方法了前台页面<asp:TemplateField HeaderText="Plant">
                        <ItemTemplate>
                            <asp:Lable ID="Plant" runat="server" Text='<%# getTest(Eval("Plant")) %>' />
                        </ItemTemplate>
                    </asp:TemplateField>
    后台代码protected string getTest(int plant)
        {
            string test = "";
            if(//条件)
            {
               //......
            }
            return test;
        }
      

  12.   

     在后台写个方法,绑定到DataField里
    或者
    在后台直接获取值,作判断