首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

有关问题:DataList下Dropdownlist操作另一个DataList下内容.

2012-01-12 
问题:DataList下Dropdownlist操作另一个DataList下内容.急我现在有2个DataList:第一个DataList从数据库中

问题:DataList下Dropdownlist操作另一个DataList下内容.急
我现在有2个DataList:
第一个DataList从数据库中读取地区信息,并在Dropdownlist中有手工添加的数字,如1,2,3,4,5,6......
第二个DataList有动态生成的产品,每个产品后面也有地区并有一个文本框。

现在要实现当我选择第一个DataList下的Dropdownlist中的数字,数字填入对应的第二个DataList下的相应地区的文本框中。

最好是实现无刷新的。

[解决办法]
可以参考以前的帖子
http://topic.csdn.net/t/20060407/13/4670056.html#
http://tag.csdn.net/Article/adf71d42-3f6b-47fa-889e-94004567a396.html
[解决办法]
// 第一个 DataList 中
// .aspx
<asp:DropDownList ID= "drpItem " runat= "server " OnSelectedIndexChanged= "drpItem_SelectedIndexChanged " AutoPostBack= "true ">
<asp:ListItem> </asp:ListItem>
<asp:ListItem Value= "red "> red </asp:ListItem>
<asp:ListItem Value= "green "> green </asp:ListItem>
<asp:ListItem Value= "orange "> orange </asp:ListItem>
</asp:DropDownList>

// .aspx.cs
protected void drpItem_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList drp = sender as DropDownList; // 触发事件的 DropDownList
DataListItem item = drp.NamingContainer as DataListItem;
string val = drp.SelectedValue;
object regionKey = DataList1.DataKeys[item.ItemIndex]; // 地区主键
foreach(DataListItem item2 in DataList2.Items) { // 遍历第二个 DataList
HiddenField fld = item2.FindControl( "fldRegionKey ") as HiddenField; // 假设此隐藏域存储了产品对应的地区主键
if(fld != null) {
TextBox txt = item2.FindControl( "MyTextBoxID ") as TextBox;
txt.Text = val;
}
}
}
[解决办法]
关于数据绑定控件中 DropDownLIst 自动回发见
http://www.cnblogs.com/Jinglecat/archive/2007/07/29/835817.html
[解决办法]
是否刷新在编代码上没有大的区别

总之都是根据地一个Dropdownlist选择的值重新绑定第二个DataList

热点排行