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 6736751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:10:00+00:00 2026-05-26T11:10:00+00:00

I have been debugging my code for a while and looking at posts in

  • 0

I have been debugging my code for a while and looking at posts in other forums, but it seems to be that everyone has a different problem than mine and what works for them will not work for me.

My dropdown list is supposed to filter a gridview by choosing all the Companies that are associated to a certain product. The solution I have found online is that most people did not have DataKeyNames set in their gridview.

I do have this set, but not to CompanyID. It wouldn’t make any sense. So I have no idea what I am supposed to do since this is the only answer I have found.

<asp:DropDownList ID="ddlCompany" runat="server" DataSourceID="dsCompanyFilter"  
DataTextField="CompanyName" DataValueField="CompanyID" AppendDataBoundItems="true" 
AutoPostBack="true">

Protected Sub ddlCompany_SelectedIndexChanged(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles ddlCompany.SelectedIndexChanged
    Dim CompanyID As Integer = ddlCompany.SelectedValue
    dsProductLookup.SelectCommand = "SELECT ProductName, CompanyID, CompanyName 
                                    FROM Product, Company 
                                    WHERE CompanyID = @CompanyID 
                                    ORDER BY ProductName"
    dsProductLookup.SelectParameters.Add("@CompanyID", ddlCompany.SelectedValue)
End Sub

<asp:gridview id="gvProducts" runat="server" AutoGenerateColumns="false" 
datakeynames="ProductID" datasourceid="dsProductLookup" style="margin-top: 12px;">

<asp:sqldatasource id="dsProductLookup" runat="server" 
Connectionstring="<%$ ConnectionStrings:ProductsConnectionString %>"
SelectCommand="SELECT ProductID, ProductName FROM [Product] ORDER BY [ProductName]">
</asp:sqldatasource>

<asp:SqlDataSource ID="dsCompanyFilter" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ProductsConnectionString %>" 
    SelectCommand="SELECT [CompanyName], [CompanyID] FROM [Company] ORDER BY CompanyName">
</asp:SqlDataSource>

UPDATE: I tried adding this to another page in my site and have the same Declaration error. Must declare the scalar variable "@CompanyID".

Choose Company: <asp:DropDownList ID="ddlCompany" runat="server" DataSourceID="dsCompanyFilter"  DataTextField="CompanyName" DataValueField="CompanyID" AppendDataBoundItems="true" AutoPostBack="true">
<asp:ListItem Enabled="true" Text="Select an option"></asp:ListItem>
</asp:DropDownList>


<asp:gridview id="gvCategories" runat="server" AutoGenerateColumns="False"
 datakeynames="CategoryID,CompanyID" datasourceid="dsCategoryLookup" emptydatatext="No 
 categories/products found." style="margin-top: 12px;">
<Columns>
    <asp:BoundField HeaderText="Category Name" DataField="CategoryName" />
    <asp:HyperLinkField DataNavigateUrlFields="ProductID" 
    DataNavigateUrlFormatString="Product/Default.aspx?ID={0}"
    DataTextField="ProductName" 
    HeaderText="Product Name" />
</Columns>
</asp:gridview>

<asp:SqlDataSource ID="dsCategoryLookup" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ProductsConnectionString %>" 
    SelectCommand="SELECT DISTINCT c.CategoryName, c.CategoryID, p.ProductName, 
                   p.ProductID, cl.CompanyID, cl.ProductID, co.CompanyID 
                   FROM Category AS c 
                   INNER JOIN CategoryLink AS l ON l.CategoryID = c.CategoryID 
                   INNER JOIN Product AS p ON p.ProductID = l.ProductID 
                   LEFT JOIN CompanyLink AS cl ON cl.ProductID = p.ProductID">
</asp:SqlDataSource>
<asp:SqlDataSource ID="dsCompanyFilter" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ProductsConnectionString %>" 
    SelectCommand="SELECT [CompanyName], [CompanyID] 
                   FROM [Company] 
                   ORDER BY CompanyName">
</asp:SqlDataSource>



 Protected Sub ddlCompany_SelectedIndexChanged(ByVal sender As Object, ByVal e As 
 System.EventArgs) Handles ddlCompany.SelectedIndexChanged
    dsCategoryLookup.SelectCommand = "SELECT Category.CategoryName, 
                                     CategoryLink.ProductID, Company.CompanyName, 
                                     Company.CompanyID, CompanyLink.CompanyID AS Expr1,
                                     Product.ProductName, Product.ProductID, 
                                     CompanyLink.ProductID AS Expr2 
                                     FROM Company 
                                     LEFT JOIN CompanyLink 
                                     ON Company.CompanyID = CompanyLink.CompanyID 
                                     LEFT JOIN Product 
                                     ON CompanyLink.ProductID = Product.ProductID 
                                     LEFT JOIN CategoryLink 
                                     ON CategoryLink.ProductID = Product.ProductID 
                                     LEFT JOIN Category  
                                     ON CategoryLink.CategoryID = Category.CategoryID
                                     WHERE Company.CompanyID = @CompanyID 
                                     ORDER BY Product.ProductName"
  • 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-05-26T11:10:01+00:00Added an answer on May 26, 2026 at 11:10 am

    I was able to find an answer on the ASP.net forum that works with my site. (So far…)

    Protected Sub ddlCompany_SelectedIndexChanged(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles ddlCompany.SelectedIndexChanged
        dsProductLookup.SelectCommand = "SELECT Company.CompanyName, Company.CompanyID,
                                         CompanyLink.CompanyID AS Expr1,
                                         Product.ProductName, Product.ProductID,
                                         CompanyLink.ProductID AS Expr2 
                                         FROM Company 
                                         INNER JOIN CompanyLink ON Company.CompanyID = CompanyLink.CompanyID 
                                         INNER JOIN Product ON CompanyLink.ProductID =                               Product.ProductID 
                                         WHERE Company.CompanyID = @CompanyID 
                                         ORDER BY Product.ProductName"
    
    dsProductLookup.SelectParameters.Clear()
    
        Dim controlParam As ControlParameter = New ControlParameter
        controlParam.ControlID = "ddlCompany"
        controlParam.DefaultValue = "-1"
        controlParam.Name = "CompanyID"
        controlParam.PropertyName = "SelectedValue"
        controlParam.Type = TypeCode.Decimal
    
        dsProductLookup.SelectParameters.Add(controlParam)
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently been put in charge of debugging two different programs which will
Have been looking at the MVC storefront and see that IQueryable is returned from
I have been asking this myself for a while. Debugging in visual studio goes
I have been debugging in GDB (C code). The issue is if I run
I have been working with AJAX for a while now, but in limited and
Is OutputDebugString(PAnsiChar('')); thread safe? I/we have been using it in threads for debugging, and
Have been studying the file system related classes of Adobe AIR 1.5, but so
Have been struggling with Javascript closure for a while trying to wrap brain around
We have been using CruiseControl for quite a while with NUnit and NAnt. For
I have been looking into IKVMing Apache's FOP project to use with our .NET

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.