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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:25:22+00:00 2026-05-26T13:25:22+00:00

This post is similar to one I have posted before about a dropdown filtering

  • 0

This post is similar to one I have posted before about a dropdown filtering results in a gridview. Well now I need this dropdown to attach itself to a repeater that will filter results into a gridview. I have tried rptLetters.DataBind() in the code behind of the dropdown list, but that doesn’t seem to be changing any of the letters at the top of the page when I click on different items in the dropdown list.

enter image description here

The screenshot doesn’t show enough of the products, but in this case it skips from G to L, and in the repeater the letters between G and L are still shown. I need to be able to get that repeater to recognize the letters that start each of the products associated with the company chosen.

<asp:Content ID="Content2" ContentPlaceHolderID="body" Runat="Server"><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>

<br /><br />Choose Company: 
<asp:DropDownList ID="ddlCompany" runat="server" AutoPostBack="true" 
 OnSelectedIndexChanged="ddlCompany_SelectedIndexChanged">
    <asp:ListItem Value="8">3rd Party</asp:ListItem>
    <asp:ListItem Value="4">BestDirect Securities</asp:ListItem>
    <asp:ListItem Value="18">Generic</asp:ListItem>
    <asp:ListItem Value="5">PFG Precious Metals</asp:ListItem>
    <asp:ListItem Value="1" Selected="True">PFGBest</asp:ListItem>
    <asp:ListItem Value="2">SFO</asp:ListItem>
    <asp:ListItem Value="6">Traders Press</asp:ListItem>
    <asp:ListItem Value="3">W&A Publishing</asp:ListItem>
</asp:DropDownList>
<asp:gridview id="gvProducts" runat="server" AutoGenerateColumns="False" 
    datakeynames="ProductID,CompanyID"  datasourceid="dsProductLookup" 
    style="margin-top: 12px;">
    <Columns>
        <asp:HyperLinkField DataNavigateUrlFields="ProductID" 
        DataNavigateUrlFormatString="Product/Default.aspx?ID={0}"
        DataTextField="ProductName" HeaderText="Product Name"
        SortExpression="ProductName" />
    </Columns>
 </asp:gridview>

<asp:sqldatasource id="dsProductLookup" runat="server" 
Connectionstring="<%$ ConnectionStrings:ProductsConnectionString %>"
SelectCommand="SELECT DISTINCT Product.ProductName, Product.ProductID, Company.CompanyID 
               FROM Product 
               LEFT JOIN CompanyLink 
               ON Product.ProductID = CompanyLink.ProductID 
               LEFT JOIN Company 
               ON CompanyLink.CompanyID = Company.CompanyID 
               ORDER BY Product.ProductName">
</asp:sqldatasource>

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

</asp:Content>


Protected Sub btnAll_Click(sender As Object, e As EventArgs)
    gvProducts.DataBind()
End Sub

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)

dsProductLookup.SelectParameters.Clear()

    Dim controlParam As ControlParameter = New ControlParameter
    controlParam.ControlID = "rptLetters"
    controlParam.DefaultValue = "-1"
    controlParam.Name = "CompanyID"
    controlParam.PropertyName = "Container.ItemIndex"
    controlParam.Type = TypeCode.String

    dsProductLookup.SelectParameters.Add(controlParam)
End Sub



Protected Sub ddlCompany_SelectedIndexChanged(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles ddlCompany.SelectedIndexChanged
    rptLetters.DataBind()
    'SELECT statement to update letter repeater
    dsLetters.SelectCommand = "SELECT DISTINCT LEFT(ProductName, 1) AS [Letter] 
                               FROM Product, CompanyLink, Company 
                               WHERE Product.ProductID = CompanyLink.ProductID 
                               AND CompanyLink.CompanyID = Company.CompanyID 
                               AND Company.CompanyID = @CompanyID"

    dsLetters.SelectParameters.Clear()
    'declaring scalar variable @CompanyID
    Dim cp As ControlParameter = New ControlParameter
    cp.ControlID = "rptLetters"
    cp.DefaultValue = "-1"
    cp.Name = "CompanyID"
    cp.PropertyName = "SelectedValue"
    cp.Type = TypeCode.Int32

    dsLetters.SelectParameters.Add(cp)
    'SELECT statement to update Gridview based on dropdown list
    dsProductLookup.SelectCommand = "SELECT Company.CompanyName, Company.CompanyID,   
                                     Product.ProductName, Product.ProductID 
                                     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()
    'declaring scalar variable @CompanyName
    Dim controlParam As ControlParameter = New ControlParameter
    controlParam.ControlID = "ddlCompany"
    controlParam.DefaultValue = "-1"
    controlParam.Name = "CompanyID"
    controlParam.PropertyName = "SelectedValue"
    controlParam.Type = TypeCode.Int32

    dsProductLookup.SelectParameters.Add(controlParam)

End Sub

UPDATE: Working code posted below. The repeater doesn’t work like a regular control so I added a hidden dropdown list to do the dirty work for the repeater. Thanks for the help!

<asp:DropDownList ID="ddlLetters" runat="server" Visible="False"   DataSourceID="dsLetters">
</asp:DropDownList>
 Protected Sub ddlLetters_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    rptLetters.DataBind()

    'SELECT statement to update letter repeater
    dsLetters.SelectCommand = "SELECT DISTINCT LEFT(ProductName, 1) AS [Letter] 
                              FROM Product, CompanyLink, Company 
                              WHERE Product.ProductID = CompanyLink.ProductID 
                              AND CompanyLink.CompanyID = Company.CompanyID 
                              AND Company.CompanyID = @CompanyID"

    'declaring scalar variable @CompanyID
    dsLetters.SelectParameters.Clear()
    Dim cp As ControlParameter = New ControlParameter
    cp.ControlID = "rptLetters"
    cp.DefaultValue = "-1"
    cp.Name = "CompanyID"
    cp.PropertyName = "ClientIDMode"
    cp.Type = TypeCode.Decimal
    dsLetters.SelectParameters.Add(cp)
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-26T13:25:22+00:00Added an answer on May 26, 2026 at 1:25 pm

    I believe the issue is that you are not updating the dsLetters SelectCommand when the user selects a new company. Right now, it selects all products without taking the selected company into account. You should be able to modify the select command in ddlCompany_SelectedIndexChanged.

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

Sidebar

Related Questions

I have an error similar to the one in this post . Now, I'm
I have a similar problem to this post . I need to display up
I have seen another post similar to this one on the website but the
I have implemented a selection pattern similar to the one described in this post
Currently I am using a post-build event command line similar to this one: xcopy
I have a similar query to the one posted here . I create a
Using the following steps: (I have checked this similar post , which does not
we've implemented a system similar to the one described in this other SO post
My question is very similar to the one described in this post: Javascript progress
I am doing a query that converts rows to columns similar to this post

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.