?
Solved

dropdown inside repeater need to find index

Posted on 2008-10-07
7
Medium Priority
?
441 Views
Last Modified: 2013-12-17
Hi all, wondering if i get some tips on how to get the index from dropdownlist inside a control. If you look at the code snippet below i need to get the basketItemId and related quantity.

thanks

<asp:Repeater ID="BasketItemRepeater" runat="server" 
                    onitemdatabound="BasketItemRepeaterDataBound">
                <ItemTemplate>                        
                  <%# DataBinder.Eval(Container.DataItem, "BasketItemId")%>
     
                            <asp:DropDownList ID="QuantityDropDownList" runat="server" AutoPostBack="True" onselectedindexchanged="UpdateQuantity" EnableViewState="true" >
                            </asp:DropDownList>                           
 
                    </ItemTemplate>
 </asp:Repeater>
 
    protected void UpdateQuantity(object sender, EventArgs e)
    {
        DropDownList d = (DropDownList) sender;
 
        // in here i need to get the basketItemId and update the quantity
    }

Open in new window

0
Comment
Question by:frosty1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 22662277
you have to iterate through the controls if they are inside of grids, repeaters, etc....
0
 

Author Comment

by:frosty1
ID: 22662450
thanks for the speedy response. In order to use Item.FindControl i have change EventArgs to RepeaterItemEventArgs. However now i am getting

Compiler Error Message: CS0123: No overload for 'UpdateQuantity' matches delegate 'System.EventHandler'

Here is my code:

          protected void UpdateQuantity(object sender, RepeaterItemEventArgs e)
    {
        DropDownList d = (DropDownList) sender;

        HiddenField basketItemId;
        basketItemId = (HiddenField)e.Item.FindControl("HiddenFieldBasketItemId");


        string mystring = d.Text + basketItemId.Value;

        Response.Write(mystring);
     

    }
0
 
LVL 21

Expert Comment

by:silemone
ID: 22662703
oh...you can't do that...you have to leave the argument that you had before in there...that's why you're getting that exception, because UpdateQuantity is expecting EventArgs e....reason being is that the sender is a Dropdownlist, so the Generic or DDL event must be associated with that sender...
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 21

Expert Comment

by:silemone
ID: 22663288
What you can do is just use the RepeaterID and access the Item.FindControl that way...
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 2000 total points
ID: 22664153
Try this:

protected void UpdateQuantity(object sender, EventArgs e)
{
	DropDownList d = (DropDownList) sender;
 
	// in here i need to get the basketItemId and update the quantity
	RepeaterItem item = (RepeaterItem)d.NamingContainer;
	int i = item.ItemIndex;   // here you get the index of the row that fires the event
	// Continue your update process with the index 
}

Open in new window

0
 

Author Comment

by:frosty1
ID: 22664345
am i using the right method or should i be using ItemCommand. Here what i've got


    protected void UpdateQuantity(object sender, EventArgs e)
    {
        DropDownList quantityDropDownList = (DropDownList)BasketItemRepeater.FindControl("QuantityDropDownList");
        string myString = quantityDropDownList.SelectedValue;
        Label2.Text = myString;
    }
0
 

Author Comment

by:frosty1
ID: 22664435
sorry i prairiedog i was writting my response to the previous post.

Anyway, working perfectly. Thanks silemone:& prairiedog very handy

I'll post the full code tomorrow for reference.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question