一个问题。关于DropDownList
我的DropDownList绑定了一个数据库表的列~
想请教的是,我怎么样才能使DropDownList里面的元素能够根据选择不同的元素可以
让DataGrid控件绑定不同的表??
问题点数:20、回复次数:6Top
1 楼hjf1223(阿不)回复于 2005-06-04 14:16:34 得分 0
在DropDownList 的 SelectedIndexChanged 事件去写代码就行了。Top
2 楼njmaxiang()回复于 2005-06-04 14:36:12 得分 0
DropDownList的AutoPostBack属性设为true然后在SelectedIndexChanged 事件去写代码Top
3 楼glatiator(C++)回复于 2005-06-04 14:54:24 得分 0
就是想问的是具体代码的写法,每选定一个DropDownList元素
都能够绑定不同的数据表到datagrid中
就象数据库中我4个表,分别是user,customer,pp,oo
我绑定user 的一个字段进DropDownList
当我从里面选择一个元素时(不同的元素连接的表不同)
可以绑定customer,pp,oo到我的datagrid中
Top
4 楼tbmlh(成林)回复于 2005-06-04 14:56:48 得分 0
楼上正解。Top
5 楼LaoDai_Net(『老代』)回复于 2005-06-04 15:08:07 得分 20
aspx code
<asp:DropDownList id="dropTable" style="Z-INDEX: 108; LEFT: 104px; POSITION: absolute; TOP: 456px"
runat="server" AutoPostBack="True">
<asp:ListItem Value="1">User表</asp:ListItem>
<asp:ListItem Value="2">customer表</asp:ListItem>
<asp:ListItem Value="3">pp表</asp:ListItem>
<asp:ListItem Value="4">00表</asp:ListItem>
</asp:DropDownList>
cs code
private void dropTable_SelectedIndexChanged(object sender, System.EventArgs e)
{
int selectValue = Int32.Parse(dropTable.SelectedItem.Value);
switch (selectValue)
{
case 1:
BindDataUser();
break;
case 2:
BindDataCustoner();
break;
case 3:
BindDataPP();
break;
case 4:
BindDataOO();
break;
default:
BindDataUser();
break;
}
}
private void BindDataUser()
{
//绑定代码略
}
private void BindDataCustoner()
{
//绑定代码略
}
private void BindDataPP()
{
//绑定代码略
}
private void BindDataOO()
{
//绑定代码略
}Top
6 楼jz630(姜喆)回复于 2005-06-04 15:11:01 得分 0
SelectedIndexChanged 事件去写代码
可根据所选的值的不同而确定执行不同的存储过程,或SQL语句。
楼主不是连查看表的SQL都不会写吧?Top




