0

I have a scenario where I want to put four identical Gridviews on the same page. (They will be on different tabs in an Ajax TabControl.) They show the same source data, but there are four corresponding groups of source data in a common underlying table. So I want to show Group 1 on Tab 1, Group 2 on Tab 2, etc. These Gridviews contain complicated controls, so I would prefer to use the same data source for all of them to avoid unnecessary repetition. The Insert and Update commands are completely identical.

So in theory I could build the Select command in such a way that I could filter the data based on the GridView that is binding to the SQLDataSource. The problem is that if I use the same SQLDataSource for all the Gridviews, I cannot find a way to have each GridView tell the SQLDataSource which one is calling it. I am thinking maybe this is not possible, because the SQLDataSource binds first before it knows what is binding to it, but I'm not sure. Can anyone think of a way to do this?

J Shantz
  • 1
  • 1

1 Answers1

0

You can change the parameter value dynamically using OnSelecting event of SQLDataSource. This can be done in server side code.

Create a property which holds your current gridview unique key, which is causing SQLDataSource to fetch data from SQL database.

Assign this property unique gridview key on DataBinding event of gridview.

Based on this property change the parameter in OnSelecting event of SQLDataSource.

Let me know if I am missing something.

Imran Rizvi
  • 7,331
  • 11
  • 57
  • 101