日期:2014-05-18 浏览次数:20993 次
string sqlstr = "Select [OrderNum],[RecDate],[respon_person] from [Order] where XiadanDate='1753-01-01 00:00:00.000'group by OrderNum,[RecDate],[respon_person]"; sqlcon = new SqlConnection(strCon); SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon); DataSet myds = new DataSet(); sqlcon.Open(); myda.Fill(myds, "try"); #region 注释 //GridView1.DataSource = myds.Tables[0]; //GridView1.DataKeyNames = new string[] { "OrderNum" };//主键 //GridView1.DataBind(); #endregion sqlcon.Close(); if (myds.Tables[0].Rows.Count > 0) { GridView1.DataSource = myds.Tables[0]; GridView1.DataKeyNames = new string[] { "OrderNum" };//主键 GridView1.DataBind(); GridView1.Visible = true; Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('有数据!!');</script>"); } else { myds.Tables[0].Rows.Add(myds.Tables[0].NewRow()); GridView1.DataSource = myds; GridView1.DataBind(); int columnCount = GridView1.Rows[0].Cells.Count; GridView1.Rows[0].Cells.Clear(); GridView1.Rows[0].Cells.Add(new TableCell()); GridView1.Rows[0].Cells[0].ColumnSpan = columnCount; GridView1.Rows[0].Cells[0].Text = "没有数据"; GridView1.RowStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center; Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('无数据!');</script>"); }