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

  • Home
  • SEARCH
  • 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 6721159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:17:48+00:00 2026-05-26T09:17:48+00:00

I would like my gridview to be filtered by the dropdown list I have.

  • 0

I would like my gridview to be filtered by the dropdown list I have. It is pulling specific information from the database, so when you choose a value from the dropdown list, it should search through all the records and find only records with the ddl value in them.

The code that I am using in the codebehind for the SelectedIndexChanged is not right though. I get an error message saying 'Value' is not a member of 'Integer'. This is on the line dsCompanyFilter.SelectParameters.Add

It probably has something to do with the gridview not tying to the dropdown list properly, but I am not sure how to fix that code. Please help!

  <asp:Content ID="Content2" ContentPlaceHolderID="body" Runat="Server"><br /><br /><br />
<asp:linkbutton id="btnAll" runat="server" text="ALL" onclick="btnAll_Click" />
<asp:repeater id="rptLetters" runat="server" datasourceid="dsLetters">
<headertemplate>
 |
</headertemplate>
<itemtemplate>
 <asp:linkbutton id="btnLetter" runat="server" onclick="btnLetter_Click" 
 text='<%#Eval("Letter")%>' />
 </itemtemplate>

<separatortemplate>
 |
</separatortemplate>
</asp:repeater>

<asp:sqldatasource id="dsLetters" runat="server" connectionstring="<%$ 
 ConnectionStrings:ProductsConnectionString %>"
 selectcommand="SELECT DISTINCT LEFT(ProductName, 1) AS [Letter] FROM [Product]">
</asp:sqldatasource>

Filter By Company:<asp:DropDownList ID="ddlCompany" runat="server" 
DataSourceID="dsCompanyFilter"  DataTextField="CompanyName" DataValueField="CompanyID">
</asp:DropDownList>
<asp:gridview id="gvProducts" runat="server" AutoGenerateColumns="False" 
datakeynames="ProductID" datasourceid="dsProductLookup" 
style="margin-top: 12px;">
<Columns>
     <asp:BoundField DataField="ProductName" HeaderText="ProductName" 
     SortExpression="ProductName" />
</Columns>

</asp:gridview>

<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]">
</asp:SqlDataSource>

</asp:Content>

This code filters the results in the gridview by Letter and the Dropdown. The problem is with the dropdown list filtering the gridview.

 Protected Sub btnLetter_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim btnLetter As LinkButton = TryCast(sender, LinkButton)
    If btnLetter Is Nothing Then
        Return
    End If
    dsProductLookup.SelectCommand = [String].Format("SELECT ProductID, ProductName 
                                                   FROM [Product] 
                                                   WHERE ([ProductName] LIKE '{0}%') 
                                                   ORDER BY [ProductName]", btnLetter.Text)
 End Sub

This is the part that has the problem. I now get the error, must declare the scalar variable @CompanyID

Protected Sub ddlCompany_SelectedIndexChanged(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles ddlCompany.SelectedIndexChanged
    dsProductLookup.SelectCommand = "SELECT ProductName, CompanyID, CompanyName 
                                     FROM Product, Company 
                                     WHERE CompanyID = @CompanyID 
                                     ORDER BY ProductName"
    dsProductLookup.SelectParameters.Add("@CompanyID", DbType.Int32, 
    ddlCompany.SelectedValue)
End Sub
  • 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-26T09:17:49+00:00Added an answer on May 26, 2026 at 9:17 am

    Deleted my previous answer.

    Actually try the following :

    dsProductLookup.SelectParameters.Add("@ProductID",
        DbType.Int32, ddlCompany.SelectedValue)
    

    No assignment to value as it is part of the Add. Noticed this when I tried to compile a test of my previous answer which didn’t work.

    EDIT: I tried the above code and it worked (did it in C#) but changed it to use DbType.Int32 for second param.

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

Sidebar

Related Questions

I would like on gridview update to get a value from a cell in
I have a gridview bound with a database. I would like to add an
I have a GridView that I would like to bind to an ObjectDataSource. I
I have a asp:GridView which contains a asp:TextBox within a TemplateField. I would like
I have a GridView, radGvA133s, on my main form, MainForm. I would like to
I have a gridview and I would like to be able to programatically change
I have a page that houses an asp GridView and I would like to
I have written the following in my gridview i would like to show only
I have DropDownList inside GridView. Now I would like to add event handler for
I have a gridview with the onRowDeleting method implemented. I would like to prompt

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.