gridview有多列,后台数据绑定,其中有一列的内容只有判断后才能显示,如:某个字段的内容是1就显示,为0就不显示,,,,这是在前台判断还是在后台判断呢,怎么判断呢?<asp:TemplateField ItemStyle-Width="8%" ItemStyle-CssClass="class1">
                                <ItemTemplate>
                                    <asp:HyperLink ID="HyperLink1" runat="server">显示这个内容</asp:HyperLink>
                                </ItemTemplate>

解决方案 »

  1.   

    http://topic.csdn.net/u/20111126/16/e3eb33f3-cabd-4002-91d5-c8c53e20b10c.html
      

  2.   

    应该是先在gridview里获取要判断的值……然后进行判断,如果为零,找到哪儿列的visibie为false,这样就可以了……你试试看
      

  3.   

    sql里也可以判断啊,查到字段为1的数据不就行了???
      

  4.   

    写个public方法放在。cs中,然后在。aspx中数据绑定时调用
      

  5.   


    //相关Row数据处理
            protected void GVDesignList_RowDataBound(object sender, GridViewRowEventArgs e)
            {             if (e.Row.RowType == DataControlRowType.DataRow)
                 {
                                       }                                    
                    Button btnDel = (Button)e.Row.FindControl("GVBtnDel");
                                   if (btnDel != null)
                    {
                        btnDel.Attributes.Add("onclick", "return confirm('你确定要删除所选择的数据行吗?');");
                    }                                             
                   //删除按钮
                    
                    if (((Label)e.Row.Cells[60].FindControl("lblAdidName")).Text.Trim() == UserName)
                    {
                        ((Button)e.Row.Cells[1].FindControl("GVBtnDel")).Enabled = true;
                    }
                    else
                    {
                        ((Button)e.Row.Cells[1].FindControl("GVBtnDel")).Enabled = false;                }                //颜色                if (((Label)e.Row.Cells[60].FindControl("GVlblactionZK")).Text.Trim() =="已实施")
                    {
                        e.Row.Cells[2].ForeColor = System.Drawing.Color.Green;
                        e.Row.Cells[3].ForeColor = System.Drawing.Color.Green;
                        e.Row.Cells[4].ForeColor = System.Drawing.Color.Green;
                        e.Row.Cells[5].ForeColor = System.Drawing.Color.Green;                 }
                    else if (((Label)e.Row.Cells[60].FindControl("GVlblactionZK")).Text.Trim() == "未实施")
                    {                    e.Row.Cells[2].ForeColor = System.Drawing.Color.Red;
                        e.Row.Cells[3].ForeColor = System.Drawing.Color.Red;
                        e.Row.Cells[4].ForeColor = System.Drawing.Color.Red;
                        e.Row.Cells[5].ForeColor = System.Drawing.Color.Red;
                    }
                    else if (((Label)e.Row.Cells[60].FindControl("GVlblactionZK")).Text.Trim() == "需确认项目")
                    {                    e.Row.Cells[2].ForeColor = System.Drawing.Color.BlueViolet;
                        e.Row.Cells[3].ForeColor = System.Drawing.Color.BlueViolet;
                        e.Row.Cells[4].ForeColor = System.Drawing.Color.BlueViolet;
                        e.Row.Cells[5].ForeColor = System.Drawing.Color.BlueViolet;
                    }
                    else if (((Label)e.Row.Cells[60].FindControl("GVlblactionZK")).Text.Trim() == "实施正确项目")
                    {                    e.Row.Cells[2].ForeColor = System.Drawing.Color.Blue;
                        e.Row.Cells[3].ForeColor = System.Drawing.Color.Blue;
                        e.Row.Cells[4].ForeColor = System.Drawing.Color.Blue;
                        e.Row.Cells[5].ForeColor = System.Drawing.Color.Blue;
                    }                //ForeColor  backColor             }        }
      

  6.   

    既然是绑定的时候 有条件不能为1或者 不能为0   为嘛不在sql里面写好了绑定呢?就and  state!=0 什么的东东
      

  7.   

    sql
    執行數據庫時判斷  decode(result,1,'顯示','不顯示')
      

  8.   

    或者在databound裏面進行判斷還有一種方法,是在後臺cs中寫好判斷的函數,IsShow(string sts)在前臺綁定的時候調用這個方法  <asp:Label ID="sts" runat="server" Text='<%#IsShow(Eval("sts").ToString())%>'   ></asp:Label>
      

  9.   

    后来判断固然可以,但是还是比较麻烦,还是在sql里面增加一个判断条件比较好
      

  10.   

    <%# Eval("sex").ToString()=="1"?"显示这个数据":""%>
      

  11.   

    Rowdatabound事件里面写!楼上有人已经给出代码了