问题描述
大家好。我有asp.net页面。我有2个存储过程来搜索城市和搜索国家。我使用2个SqlDataSource。搜索city的SqlDataSource1和搜索country.my问题的SqlDataSource2是我想使用dropdownlist1选择搜索类型。当选择索引为0时,运行SqlDataSource1。当
选择索引为1时,SqlDataSource2将在单击按钮事件上运行。我的代码:
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:
GridView1.DataSourceID = "SqlDataSource1";
GridView1.DataBind();
请帮帮我。
我尝试了什么:
如何通过dropdownlist selectedindex == 0运行SqlDataSource1而通过dropdownlist selectedIndex运行SqlDataSource2 == 1
please help me.
What I have tried:
how to Run SqlDataSource1 by dropdownlist selectedindex ==0 and SqlDataSource2 by dropdownlist selectedindex ==1
推荐答案
if (DropDownList1.SelectedIndex == 1)
GridView1.DataSourceID = "SqlDataSource2";
else
GridView1.DataSourceID = "SqlDataSource1";
GridView1.DataBind();
或者使用三元运算符
Or use the ternary operator thus
GridView1.DataSourceID = DropDownList1.SelectedIndex == 1 ? "SqlDataSource2" : "SqlDataSource1";
GridView1.DataBind();
这篇关于如何通过dropdownlist selectedindex == 0和sqldatasource2 by dropdownlist selectedindex == 1运行sqldatasource1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!