Link to home
Start Free TrialLog in
Avatar of AlHal2
AlHal2Flag for United Kingdom of Great Britain and Northern Ireland

asked on

return selected row from filtered grid

I'm using ASP.net 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" />
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
            </Columns>
           
        </asp:GridView>
</asp:Panel>

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
as
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?
Avatar of Umar Topia
Umar Topia
Flag of India image

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
Avatar of AlHal2

ASKER

Please could you go into more detail?  I haven't used commandArgument before.  I saw this article online, but it didn't help much.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandargument(v=VS.80).aspx
ASKER CERTIFIED SOLUTION
Avatar of AlHal2
AlHal2
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AlHal2

ASKER

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