Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6683513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:49:49+00:00 2026-05-26T04:49:49+00:00

This may be a fairly simple question, but I can’t seem to find the

  • 0

This may be a fairly simple question, but I can’t seem to find the answer I’m looking for.

I’ve been working with a GridView control programmatically, loading it from a dataset in the code behind. So it’s a fairly simple process, instantiate a new Gridview, load the Dataset, bind the data, and then load the control.

However, I’m running into an issue where I can’t load directly into the GridView from the code. In the .aspx file I have a simple:

<asp:GridView ID="Supp_Data" runat="server" /> 

In the code behind my creation of the GridView is as follows:

Supp_Data = new GridView();
Supp_Data = OutsideClass.GetData(str_sql); 
//Add other features here (such as AllowSorting, GridLines, PageSize, etc.)

Supp_Data.DataBind();

And in my outside class:

public static GridView GetData(string str_sql)
{
    // string str_sql is simply the sql query that we will get the dataset with.         

    OdbcConnection dbc_conn = ODBC_Conn("");  //This simply instantiates the connection
    OdbcCommand dbc_cmd = null;
    OdbcDataAdapter dbc_adpt = null;
    DataSet dta_ds = new DataSet();
    GridView ret_val = new GridView();
    try
    {
        if (dbc_conn.State != System.Data.ConnectionState.Open) { dbc_conn.Open(); }
        dbc_cmd = new OdbcCommand(str_sql, dbc_conn);
        dbc_adpt = new OdbcDataAdapter(dbc_cmd);
        dbc_adpt.Fill(dta_ds);
        ret_val.DataSource = dta_ds;
        ret_val.DataBind();
        dbc_conn.Close();
    }
    catch (Exception e) 
    {
        string tst_msg = e.Message;
    }
    return ret_val; 
}

But this doesn’t display the grid at all.

Now, as a workaround (which displays the data), adding a PlaceHolder in the .aspx file and using PlaceHolder.Controls.Add(Supp_Data) displays the data just fine.

So my actual question is, why doesn’t the data get displayed in the GridView, but has no problem displaying in the PlaceHolder? Does it have something to do with the Page Life Cycle that I’m overlooking (I tried with both Page_Load and Page_Init with the same results)? This would definitely help my overall understanding of this process. I just don’t understand why it would work near perfectly with one but not with the other.

Thanks for any information.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:49:50+00:00Added an answer on May 26, 2026 at 4:49 am

    You shouldn’t do a ‘new’ on the GridView, just populate it’s DataSource and call DataBind. The object that the page was referencing is being overwritten in your function call so it has nothing to display.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm fairly new to Android programming, so this may be a simple question, but
This seems to me like a very simple question, but I can't seem to
This may be a fairly simple question, but my goal here is to redirect
This question may sound fairly elementary, but this is a debate I had with
This may seem like a daft question, but i was wondering about how to
This seems like a really simple question; but I can't see how it's actually
(I'm fairly certain the answer to this question is quite simply no but I
I am fairly new to OSX development, so this may be easy but google
This may seem like a programming 101 question and I had thought I knew
This may be simple one, but 5 mins of Googling didn't give me the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.