Asp.net GridView - how to access datasource before data is bound?

I'm trying to access datasource before I bind it to grid. How do I do that? My guess I should look in one of the events like Grid.DataBinding


Yes, the GridView.DataBinding event will be raised prior to the control being bound. You can access the DataSource control in that event and make modifications if you so desire (for example, modifying parameters).

protected void Grid_DataBinding(object sender, EventArgs e) { mySqlDataSource.SelectCommand = "Select * from Stars"; }


One way would be to not define the datasource on the grid itself. In the page_load, create and populate your datasource and then dynamically bind it to your datagrid. That way you would be able to access it.

Hope it helps!


  • How to get the key state via a scancode (not virtual keycode)?
  • Disable (or filter) Hot Corners
  • GridBag Layout How to push components north
  • Add-In Commands Ribbon shows in Excel Online but not in Excel for Windows
  • how to get DAYS absent from working days from given date range?
  • AWS SES Production Access setup with Meteor
  • Why does Internet Explorer sometimes trigger a local storage event before the data's ready? [du
  • How to wait till webViewDidFinishLoad gets completed
  • Insert null in a database
  • Intellij Idea Terminal shortcut not working
  • How can I merge my files when the folder structure has changed using Borland StarTeam?
  • Change border corlor of NSTableView
  • proxy request in node.js / express
  • How to protect the mp3 file from read or copy on Android?
  • jQuery Mobile - Dialogs without changing hash
  • Cryptic error when trying to run POW
  • Calling C function from lua
  • Entity Framework ObjectContext: Concurrency
  • Nested projects in multiproject visual studio templates
  • Is is safe to use HSQLDB for production? (JBoss AS5.1)
  • Is there a way to disable a specific event in kendo ui scheduler?
  • Change Checkbox value without raising event
  • Knockout custom binding handler
  • Filter strings with regex before casting to numeric
  • TextToSpeech.setEngineByPackageName() triggers NullPointerException
  • d3 v4 drag and drop with TypeScript
  • Time complexity of a program which involves multiple variables
  • JQuery Internet Explorer and ajaxstop
  • Word Open XML Mail Merge
  • How do I alternate colors in Flat List (React Native)
  • QLineEdit password safety
  • Nant, Vault & Windows Integrated Authentication
  • jQuery show() function is not executed in Safari if submit handler returns true
  • Opengl-es onTouchEvents problem or a draw problem? [closed]
  • Bug in WPF DataGrid
  • jQuery tmpl and DataLink beta
  • How can I estimate amount of memory left with calling System.gc()?
  • How to get Windows thread pool to call class member function?
  • Linking SubReports Without LinkChild/LinkMaster
  • Is there any way to bind data to data.frame by some index?