Click here to Skip to main content
16,016,623 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all. I have asp.net page . I have 2 stored procedure to search city and to search country. I use 2 SqlDataSource. the SqlDataSource1 for search city and the SqlDataSource2 for search country.my problem is that I want use dropdownlist1 for select type of search.when selected index is 0 the SqlDataSource1 be run. and when
selected index is 1 the SqlDataSource2 be run.my code on click button event:
C#
GridView1.DataSourceID = "SqlDataSource1";
               GridView1.DataBind();


please help me.

What I have tried:

how to Run SqlDataSource1 by dropdownlist selectedindex ==0 and SqlDataSource2 by dropdownlist selectedindex ==1
Posted
Updated 28-Jun-16 0:47am
v2

1 solution

So what is the problem? Just use an if-statement e.g.
C#
if (DropDownList1.SelectedIndex == 1)
    GridView1.DataSourceID = "SqlDataSource2";
else
    GridView1.DataSourceID = "SqlDataSource1";
GridView1.DataBind();

Or use the ternary operator thus
C#
GridView1.DataSourceID = DropDownList1.SelectedIndex == 1 ? "SqlDataSource2" : "SqlDataSource1";
GridView1.DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900