return selected row from filtered grid

Posted on 2011-10-17
Last Modified: 2012-05-12
I'm using 2.0 with vb 2005 and sql 2005.  
When I filter the gridview and press select (using the hyperlink on the grid - see below) on a row I'm getting a completely different row.  It's as though the select button is working on the unfiltered gridview.
The gridview is like this.

<asp:Panel ID="Panel1" runat="server" ScrollBars="Both" Height="480px" Width="100%">

        <asp:GridView  ID="Gridview1" runat="server" AllowSorting="True" Font-Names="Arial"
        Font-Size="Small"   RowStyle-Wrap="False" BackColor="White" BorderColor="Silver"  
        DataKeyNames="PrimaryKey"  >
            <RowStyle Wrap="False" />
                <asp:CommandField ShowSelectButton="True" />

When the user selects items to filter the filters are passed to a stored proc as a parameter.

create proc [dbo].[SP]
@ExtraFilters nvarchar(MAX)=null
Declare @strsql nvarchar(max)

set @strsql='
 select *
          from Xref xref (nolock)
            inner join Future fut (nolock)
            on xref.root = fut.root
            inner join Master m (nolock)
            on fut.RIC = m.RIC
where '+  @ExtraFilters +
' order by xref.root

exec (@strsql)

When I press select alongside a grid row, how can I make it select a row from the filtered gridview as opposed to the unfiltered gridview?
Question by:AlHal2
    LVL 10

    Expert Comment

    by:Umar Topia
    You can bind your primary key column name as a CommandArgument property of your button inside gridview.

    then @ server side, while processing the event, you can get the commandargument property to read the ID

    Author Comment

    Please could you go into more detail?  I haven't used commandArgument before.  I saw this article online, but it didn't help much.

    Accepted Solution

    I've created a text box to store the extra filters.  I preserve the values with this command in the form load event.

    Me.TxtExtraFilters.Text = Request(Me.TxtExtraFilters.UniqueID)

    The only problem is the text box has to be visible.  Am I missing something?

    Author Closing Comment

    For now my solution works.  Since I couldn't use the other I must withhold the points.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Suggested Solutions

    Title # Comments Views Activity mvc - Time 37 45
    ASP.NET MVC Jquery 17 41
    Syntax question II 2 26
    PDF Embed pdfobject.js local path problem regular ASP 2 45
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    794 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

    17 Experts available now in Live!

    Get 1:1 Help Now