0

I am encountering a strange problem in the past 3 days, although that query return data the datagrid does not show either any data or any columns (I am fairly new to ASP but I dont think the code has any problem).

here is the code

protected void Page_Load(object sender, EventArgs e)
        {
            DataSet UserInfoFromDB = FillTableInfo();
            GridViewData.DataSource = UserInfoFromDB.Tables[0];
            GridViewData.AutoGenerateColumns = true;
        }

the load calling this function to get all the data, I have already tested the output and its returning the data as it should be but the datagrid seems empty.

public DataSet FillTableInfo(){
            var Query = "SELECT * FROM [dbo].[orders] ;";
            SqlDataAdapter DataAdapter = new SqlDataAdapter(Query, CreateConnectionstring());
            SqlCommandBuilder commandBuilder = new SqlCommandBuilder(DataAdapter);
            DataSet DataSetVariable = new DataSet();
            DataAdapter.Fill(DataSetVariable);
            return DataSetVariable;
        }

I have changed only the gridview id so far

Thank you in advance

MrValvis
  • 107
  • 1
  • 10

1 Answers1

1
use the Databind() method

    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet UserInfoFromDB = FillTableInfo();
        GridViewData.DataSource = UserInfoFromDB.Tables[0];
        GridViewData.DataBind();
        GridViewData.AutoGenerateColumns = true;
    }
SANDEEP
  • 1,062
  • 3
  • 14
  • 32
  • Thank you very much , I will put this article here for anyone who might need some further explenation https://stackoverflow.com/questions/983981/why-is-the-databind-method-necessary – MrValvis May 27 '20 at 16:09