SqlConnection conn = new SqlConnection(ConnectionString);
            DataSet ds = new DataSet();
            string cmd = "SELECT [ID],[Datetime],[UserName],[Fault],[Content],[Telephone],[Mark] FROM [Report].[dbo].[Reports] order by datetime Desc";
            ds = SqlHelper.ExecuteDataset(conn, CommandType.Text, cmd);            GridView_List.DataSource = ds.Tables[0];
            GridView_List.DataBind();
他全部都显示了,我现在需要把ID这列隐藏,因为我还需要用ID字段。

解决方案 »

  1.   

    aspx:<Columns>中去掉 ID 列啊
      

  2.   

    加一个RowDataBound事件
    对数据行的列进行隐藏e.Rows.Cell[0].Visible = false;
      

  3.   

    如果不是自动生成列,通过前台去绑定你要显示的列,就可以在前台控制。
    如果是在前台脚本中要到id,用隐藏的办法前台就取不到值。
    这样的话,就绑定的时候,把id绑定到隐藏控件中,在获取值
      

  4.   

       <Columns>
                                                 <asp:TemplateField>
                                                    <headertemplate>
                                                        <asp:checkbox id="checkall" runat="server" />                      
                                                      
    </headertemplate>
                                                     <itemstyle width="20px" />
                                                    <itemtemplate>
                                                        <input type="hidden" id="grdGoodID" value="<%# Eval("ID") %>" />>" />                                                    
    </itemtemplate>
                                                </asp:TemplateField>
      

  5.   

    在GridView的PreRender事件中:
        protected void GridView1_PreRender(object sender, EventArgs e)
        {
            GridView1.Columns[列号].Visible = false;
        }
      

  6.   

    隐藏只需设置ID列的Visible属性false即可,但以后还需要用ID字段的话,就需要把ID列转换成模板列。
    编辑ID模板列,为项目的Label命个名,假设为lb_ID
    在以后要取ID值
    GridView1.Rows[i].Cells[0].FindControl("lb_ID").Trim();//i为行号
      

  7.   

     加上aspx页面的列上 加上  style="Visibility:hidden"
      

  8.   

    在aspx页面的列上 加上  style="Visibility:hidden"
      

  9.   

    autogenrtatecolumn为FALSE 再改好了
      

  10.   

    我给控件里面加了一个HyperlinkField,里面的Cells[1]就不能用了,还有什么方法用代码可以解决这个问题??