Solved

dropdown inside repeater need to find index

Posted on 2008-10-07
7
440 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 500 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

688 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