还有一个系部专业表,见图:
要在Repeater控件显示和修改学生信息,其中有个两个DropDownList,分别显示学生的系部和对应的专业。
比如点击一个学生,然后要在系部专业中显示该生所在的系和专业,然后我点击系部的DropDownList,更改其他的系,下面的专业DropDownList也相应的改变,但是SelectedIndexChanged事件总是无法实现,没有反映,请高人解答
系部:<asp:DropDownList ID="dropsDep" runat="server" AutoPostBack="True" onselectedindexchanged="dropsDep_SelectedIndexChanged" Width="7em"></asp:DropDownList><br />专业:这个是怎么回事,有大侠给个例子吗?
<asp:DropDownList ID="dropsMajor" runat="server" Width="6em"></asp:DropDownList>
3 个解决方案
#1
经测试,可以响应onselectedindexchanged事件啊
<asp:repeater id="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound">
<itemtemplate>
<div>
<asp:dropdownlist id="drpUserList" autopostback="true" onselectedindexchanged="myDrop_SelectedIndexChanged" runat="server"></asp:dropdownlist>
</div>
</itemtemplate>
</asp:repeater>
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem||e.Item.ItemType==ListItemType.EditItem)
{
DropDownList myDrop = e.Item.FindControl("drpUserList") as DropDownList;
if (myDrop.Items.Count == 0)
{
myDrop.Items.Add(new ListItem("a", "1"));
myDrop.Items.Add(new ListItem("b", "2"));
myDrop.DataBind();
}
}
}
protected void myDrop_SelectedIndexChanged(object sender,EventArgs e)
{
Response.Write(((DropDownList)sender).SelectedIndex.ToString());
}
#2
同意!
#3
LZLZ 我也按你的做了 可是 dropdownlist如果在repeater外 事件会触发 如果在repeater里面咋不触发事件呢??
#1
经测试,可以响应onselectedindexchanged事件啊
<asp:repeater id="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound">
<itemtemplate>
<div>
<asp:dropdownlist id="drpUserList" autopostback="true" onselectedindexchanged="myDrop_SelectedIndexChanged" runat="server"></asp:dropdownlist>
</div>
</itemtemplate>
</asp:repeater>
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem||e.Item.ItemType==ListItemType.EditItem)
{
DropDownList myDrop = e.Item.FindControl("drpUserList") as DropDownList;
if (myDrop.Items.Count == 0)
{
myDrop.Items.Add(new ListItem("a", "1"));
myDrop.Items.Add(new ListItem("b", "2"));
myDrop.DataBind();
}
}
}
protected void myDrop_SelectedIndexChanged(object sender,EventArgs e)
{
Response.Write(((DropDownList)sender).SelectedIndex.ToString());
}
#2
同意!
#3
LZLZ 我也按你的做了 可是 dropdownlist如果在repeater外 事件会触发 如果在repeater里面咋不触发事件呢??