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

你可能感兴趣的:(list)