简体   繁体   English

Gridview数据源未更新

[英]Gridview DataSource doesn't update

With a button press I'm trying to update the GridView on my ASP.net site with Database from SQL server with other table but it doesnt change, there is no "catch". 按下按钮,我试图使用SQL Server和其他表通过数据库更新ASP.net站点上的GridView,但它没有变化,没有“捕获”。

The GridView doesn't appear. GridView不会出现。

    {
        SqlConnection sqlConnection1;
        sqlConnection1 = new SqlConnection(@"Data Source=ELAD_HA\SQLEXPRESS;Initial Catalog=Users;Integrated Security=True");
        SqlCommand sqlCommand1;
        sqlCommand1 = new SqlCommand("SELECT * FROM TBUsers ORDER BY Name", sqlConnection1);
        try
        {
            DataSet ds = new DataSet();
            SqlDataAdapter adptr = new SqlDataAdapter(sqlCommand1);
            SqlCommandBuilder comb = new SqlCommandBuilder(adptr);
            adptr.Fill(ds,"T1");

            GridView2.DataSource = ds.Tables["T1"];

            //GridView2.DataSource = ds;
            //GridView2.DataMember = "T1";
        }
        catch (SqlException ex)
        {
            SuccessLabel1.Text = ex.Message.ToString();
        }
    }

What is wrong with the code? 代码有什么问题?
PS PS
can I changed the DataSource to a GridView that I chose a Data Source from its menu ? 我可以将DataSource更改为从菜单中选择数据源的GridView吗? (from the "split" screen). (从“拆分”屏幕)。

Thanks for the helpers. 谢谢你的帮手。

Try calling databind to update the content: 尝试调用databind来更新内容:

GridView2.DataBind();

Best regards 最好的祝福

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM