Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8987795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:52:36+00:00 2026-06-15T21:52:36+00:00

I”ve been working at this for a good while now. I’m simply trying to

  • 0

I”ve been working at this for a good while now. I’m simply trying to access something that is in a datalist. I can get items just fine from the PageLoad, even set some dynamic items.. but I can’t acess controls from my button click handler.
I’ve tried other variations such as

ListView1.FindControl("DropDownList1") as DropDownList;

Which gives a NULL.
I’ve tried

<asp:LinkButton id="addPro" runat="server" CommandArgument='<%# DropDownList1.SelectedItem.Text %>' onCommand ="addPro_Click">Add To Cart</asp:LinkButton>

Which says it can’t find the data control in scope.

    <asp:ListView ID="ListView1" runat="server" 
        DataKeyNames="Expr7,Expr1,productNo" DataSourceID="SqlDataSource1">
        <AlternatingItemTemplate>
            <span style="">
            <asp:Label ID="productNameLabel" runat="server" 
                Text='<%# Eval("productName") %>' />
            <br />
            <asp:Image runat="server" height = "300" ImageUrl='<%# Eval("img") %>'></asp:Image>
            <br />
            Description:<br />
            <asp:Label ID="itemNotesLabel" runat="server" Text='<%# Eval("itemNotes") %>' />
            <br />

            stock:
            <asp:Label ID="stockLabel" runat="server" Text='<%# Eval("stock") %>' />
            <br />
            price:
            <asp:Label ID="priceLabel" runat="server" Text='<%# "$"+ Eval("price")+".00" %>' />
            <br />

            Quantitiy: <asp:DropDownList id="DropDownList1" runat="server"> </asp:DropDownList>            
            <br />

            <asp:LinkButton id="addPro" runat="server" CommandArgument='<%# Eval("productNo") %>' onCommand ="addPro_Click">Add To Cart</asp:LinkButton>
            <br /><br /><br />
<br /></span>
        </AlternatingItemTemplate>

On click

protected void addPro_Click(Object sender, CommandEventArgs e)
{
    string addr = "";
    string v = Request.QueryString["cat"];
    if (v != null)
    {
        v = "cat=" + v+"&";
    }
    else
    {
        v = "";
    }

    DropDownList stockDD = (DropDownList) FindControl("DropDownList1");
    if (stockDD != null)
        addr = "~/product.aspx/?" + v + "add=" + e.CommandArgument.ToString() + "&quant=" + stockDD.SelectedItem.Text;
    else
        addr = "ERROR!";
    Response.Redirect(addr+e.CommandArgument.ToString());        
    ListView1.ItemDataBound += (sa, ea) =>
        {
            DropDownList stockD = ea.Item.FindControl("DropDownList1") as DropDownList;
            Label l = ea.Item.FindControl("Lable12") as Label;
            l.Text = stockD.SelectedItem.Text;
            addr = "~/product.aspx/?" + v + "add=" + e.CommandArgument.ToString() + "&quant=" + stockD.SelectedItem;

        };
  // Response.Redirect(addr);
}

Any help in the right direction will help a ton! Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:52:37+00:00Added an answer on June 15, 2026 at 9:52 pm

    Try this:

    LinkButton lbSender = (LinkButton)sender;
    ListViewDataItem lvItem = (ListViewDataItem)(lbSender.Parent);
    DropDownList DropDownList1 = lvItem.FindControl("DropDownList1");
    

    ListView.Items is a collection of ListViewDataItem which inherits ListViewItem, which inherits from Control. This means you can find any control in its Controls collection using FindControl. You just have to look at the heirarchy.

    Docs for ListView: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.aspx

    Docs for ListViewDataItem: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listviewdataitem.aspx

    Docs for ListViewItem: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listviewitem.aspx

    Docs for Control: http://msdn.microsoft.com/en-us/library/system.web.ui.control.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
in this code I'm trying to Listening to multi connection at the same time
Does anyone know how can I replace this 2 symbol below from the string
i'm trying to setup django on nginx + gunicorn on a centos6 server (firewall
This is in Visual Studio 2010 IDE. I need to remove the quotes from
I've got a string that has curly quotes in it. I'd like to replace
Why does the following segfault, and how can I prevent it? <?php $str =
I'm looking for a way to convert text like this: <!DOCTYPE html PUBLIC \-//W3C//DTD
I have a simple HTML5 page that I'm building to figure some things out
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.