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字段。
对数据行的列进行隐藏e.Rows.Cell[0].Visible = false;
如果是在前台脚本中要到id,用隐藏的办法前台就取不到值。
这样的话,就绑定的时候,把id绑定到隐藏控件中,在获取值
<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>
protected void GridView1_PreRender(object sender, EventArgs e)
{
GridView1.Columns[列号].Visible = false;
}
编辑ID模板列,为项目的Label命个名,假设为lb_ID
在以后要取ID值
GridView1.Rows[i].Cells[0].FindControl("lb_ID").Trim();//i为行号