?
Solved

return selected row from filtered grid

Posted on 2011-10-17
4
Medium Priority
?
238 Views
Last Modified: 2012-05-12
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?
0
Comment
Question by:AlHal2
  • 3
4 Comments
 
LVL 10

Expert Comment

by:Umar Topia
ID: 36978828
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
0
 

Author Comment

by:AlHal2
ID: 36978876
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
0
 

Accepted Solution

by:
AlHal2 earned 0 total points
ID: 36980437
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?
0
 

Author Closing Comment

by:AlHal2
ID: 37013461
For now my solution works.  Since I couldn't use the other I must withhold the points.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month16 days, 3 hours left to enroll

850 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