SIGN UP MEMBER LOGIN:    
ARTICLE

How to handle Drop-Down event in Repeater control

Posted by Prasham Sabadra Articles | ASP.NET Controls in C# February 24, 2010
In this article we will see how to handle Drop-Down event in Repeater control and getting the current Item index of Repeater control.
Reader Level:

In my project I have to handle the event of drop-down control in repeater control and also want the current item index. I get how to handle the event but I need to burn my midnight's oil to get the current item index and finally I got the solution using NamingContainer property. 

Following is the sample code for repeater control and drop-down control in it

<asp:Repeater ID="myRepeater" runat="server">
 <ItemTemplate>
  <asp:DropDownList ID="myDropdown" runat="server" AppendDataBoundItems="true"    AutoPostBack="true" OnSelectedIndexChanged="myDropdown_SelectedIndexChanged">
</asp:DropDownList>
</ItemTemplate>
 </asp:Repeater>

Added the event myDropdown_SelectedIndexChanged to the code behind as follows : 

protected void myDropdown_SelectedIndexChanged(object sender, EventArgs e)
{
    // Get the drop down instance as follows
    DropDownList myDropdown = sender as DropDownList;
    // Get the current item index
    int currentItemIndex = ((RepeaterItem)drpVariants.NamingContainer).ItemIndex;
}

Here we are getting the RepeaterItem using the Namingcontainer property. Here Repeater control is naming container. i.e. - it provides unique ids to its child controls. Here is the very good blog on NamingContainer.

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Gauge for SharePoint
Become a Sponsor