Repeater嵌套dropdownlist控件

<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());
    }

原文出处:http://hi.baidu.com/imouse728/blog/item/37d16826610ee0118b82a117.html

原文地址:https://www.cnblogs.com/qdhjbym/p/2103052.html