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 3227254
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:33:10+00:00 2026-05-17T16:33:10+00:00

In the past, I have populated GridView’s with ‘manually created’ data sources in the

  • 0

In the past, I have populated GridView’s with ‘manually created’ data sources in the code behind, by doing this in the Page Load:

DataTable myData = SomeMethod(); //Returns a DataTable
myGrid.DataSource = myData;
myGrid.DataBind();

and whenever I wanted to download the data to a CSV file, I’d just add the following to the button’s Click event:

DataTable csvData = new DataTable();
csvData = (DataTable)myGrid.DataSource;

//CSV construction, reponse send to browser, etc.

This works because the GridView is already databound during Page Load, so the data is available when the Click event is reached.

But now I can’t get it to work using a SqlDataSource control that I added in design time (HTML). This SqlDataSource is bound to a DropDown control with auto-postback, so that data is retrieved when the selection is changed.

I run the website, with data already displayed in the GridView (EnableViewState=false to force query at each page load), and click the button, only to get an exception caused by the fact that myGrid.DataSource is null.

My question (finally):
I’ve noticed that the click event occurs before GridView_OnDataBound, but even OnDataBound the datasource is null. How can I get the data from the rendered GridView to allow the donload? Or from where should I attempt to retrieve it?

  • 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-17T16:33:11+00:00Added an answer on May 17, 2026 at 4:33 pm

    When using design time data sources, the DataSource property is not used. Instead the DataSourceID property is used, but all it contains is the name of the data source control. You will have to go back to your SQLDataSource to get the information you need for exporting.

    DataView dv = (DataView)sqlDataSource.Select(DataSourceSelectArguments.Empty); 
    DataTable dt = dv.ToTable(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the past I have used the following method to parse the json data
I have been doing TDD for the past 3 years. We were a small
In the past I have used MAPISendMail to launch Outlook (or whatever the desired
In the past I have used Managed Direct X and DirectShow.Net to play a
In the past I have worked with the microchip PIC family, but I would
In the past I have stored database credentials (username, password) in another file (outside
I have question regarding the use of function parameters. In the past I have
I haven't searched real hard recently but in the past I have searched high
Excuse my limited knoweldge here. In the past I have used Steve Sanderson's method
There have been several questions over the past few days about the proper use

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.