<table> <tr style=" color:Black; background-color:SkyBlue; font-weight:bold;" > <th scope="col" style="10px;"> </th> <th scope="col" style="190px;">编号</th> <th scope="col" style="194px;">名称</th> <th scope="col" style="190px;">日期</th> <th scope="col" style="100px;">周期(周)</th> <th scope="col" style="110px;">详细</th> </tr> </table>
然后,在后台代码中加上没有数据时的显示表头的方法(方法如下),当然在加入该方法前需要判断是否有数据。
private void bindULData() { SqlConnection sqlCon = new SqlConnection("server=.;database=testUL;uid=sa;pwd=sa"); SqlCommand sqlCom = new SqlCommand("select * from UserInfo where FID = 10", sqlCon); SqlDataAdapter sda = new SqlDataAdapter(sqlCom); DataSet ds = new DataSet(); sda.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { this.GridView1.DataSource = ds; this.GridView1.DataBind(); } else { DataTable dt = new DataTable(); this.GridView1.DataSource = dt; this.GridView1.DataBind(); } }