日期:2014-05-18  浏览次数:20993 次

gridview绑定的dataset,里面却是是有数据的,但是前台页面就是不显示。更为奇怪的是,我居然可以更新和删除
gridview绑定的dataset,里面却是是有数据的,但是前台页面就是不显示。gridview绝对有数据,我用了if判断。更为奇怪的是,我居然可以更新和删除,在数据库里可以看到,确实是更新和删除了。
C# code


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>");
        }





------解决方案--------------------
直接
AutoGenerateColumns="True"
就能显示
计算机不会撒谎的
------解决方案--------------------
前台绑定,或者增加AutoGenerateColumns="True"

------解决方案--------------------
前台绑定,或者增加AutoGenerateColumns="True"
 

------解决方案--------------------
前台绑定,或者增加AutoGenerateColumns="True"