Solved

dropdown inside repeater need to find index

Posted on 2008-10-07
7
433 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
  • 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now