How to re-use one SqlDataSource for mutiple grids with different parameters
-
I need to display four GridViews at once, but the data they contain differs in each grid by one parameter. It seems clumsy to add four identical SqlDataSource controls, so is there some way I can re-use one?
-
I need to display four GridViews at once, but the data they contain differs in each grid by one parameter. It seems clumsy to add four identical SqlDataSource controls, so is there some way I can re-use one?
you can use stored procedure and bind one sqldatasource to that stored procedure. you can write down all the four queries with different parameters into your stored procedure using if loop instead of using four sqldatasources. for that you have to add one more parameter for identify the query from the loop. for example: @count int, @a varchar(50), @b varchar(50), @c varchar(50), @d varchar(50) if(@count=1) begin Query1 with parameter @a end if(@count=2) begin Query2 with parameter @b end if (@count=3) begin Query3 with parameter @c end if (@count=4) begin Query4 with parameter @d end