http://www.cnblogs.com/345563452/archive/2009/03/19/1417037.html




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

分类: ASP.NET


本文转载:CSDN博客