binding in gridview RRS feed

  • Question

  • User932259438 posted


    I tried with debug and I got results in dataset visualizer but not binding in gridview.

    My datatable:


    private static DataTable GetSlipDataTable()
            DataTable Slip_DataTable = new DataTable();
            if (HttpContext.Current.Session["slip"] != null)
                Slip_DataTable = (DataTable)HttpContext.Current.Session["slip"];
                Slip_DataTable.Columns.Add(new DataColumn("BettingSlipNr"));
                Slip_DataTable.Columns.Add(new DataColumn("DateOfEvent"));
                Slip_DataTable.Columns.Add(new DataColumn("NameOfEvent"));
                Slip_DataTable.Columns.Add(new DataColumn("TypeOfBets"));
                Slip_DataTable.Columns.Add(new DataColumn("Pick"));
                Slip_DataTable.Columns.Add(new DataColumn("Odds"));
                Slip_DataTable.Columns.Add(new DataColumn("OddsId"));
                Slip_DataTable.Columns.Add(new DataColumn("Stake"));
                Slip_DataTable.Columns.Add(new DataColumn("StakeSum"));
                Slip_DataTable.Columns.Add(new DataColumn("EventId"));
                Slip_DataTable.Columns.Add(new DataColumn("SilpType"));
                Slip_DataTable.Columns.Add(new DataColumn("IsDisplayMessage"));
                Slip_DataTable.Columns.Add(new DataColumn("IsLiveEvent"));
                Slip_DataTable.Columns.Add(new DataColumn("IsLiveEventBetChanged"));
            return Slip_DataTable;
            DataTable Slip_DataTable = GetSlipDataTable();

    My data table is not empty and I want to binding

    Like that:

     Session["slip"] = Slip_DataTable;
            GridView1.DataSource = Slip_DataTable;

    Not working.

    What is wrong in my code?

    Monday, May 16, 2016 1:18 PM

All replies

  • User-1780421697 posted

    Make sure that Gridview have autogeneratedcolumn= true otherwise it will not display any data.

    What is problem, is there any error while binding or null exception or is there empty gridview?

    Monday, May 16, 2016 1:34 PM
  • User1559292362 posted

    Hi progy85,

    What is wrong in my code?

    According to your code snippet, if the value of session variable named HttpContext.Current.Session["slip"] is null, it seems that the variable named Slip_DataTable doesn't have any rows. please debug your code check if the variable named Slip_DataTable has some rows by using the following code.

    DataTable Slip_DataTable = GetSlipDataTable();
    int count = Slip_DataTable.Rows.Count;

    In addition, could you please provide your ASPX page code and error message if it has.

    Best regards,

    Cole Wu

    Tuesday, May 17, 2016 6:24 AM