?
Solved

Use select button in gridview to move to a new page

Posted on 2007-10-04
12
Medium Priority
?
213 Views
Last Modified: 2008-01-09
I am fairly new to asp.net 2.0.  I have run into a problem with the gridview and I need help.  I have a drop down window.  I choose an item in the window and the gridview populates information based on the item that I have chosen.  Now, I want to click on the select button next to the row in the gridview and display a new page with detail information pertaining to that one row.  This detail information that is being displayed on a different page needs to pull data from a different table based on a particular field in the row on the previous page that I have selected.  I hope this makes sense.  Can anyone help?
0
Comment
Question by:spectre921
  • 6
  • 5
12 Comments
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 20019719
Without being too particular could you not use a hyperlink column to send querystring parameters to the other page?
0
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 20019788
If you don't want to do it that way, then you could set up the select button to send your datakey to a function that sets the key as a session variable and then does a transfer or redirect to the other page, where the session variable is then used to query the database for your item.
0
 
LVL 10

Expert Comment

by:digitalZo
ID: 20019814
Add a Button Template to the GridView:

<Columns>
          <asp:TemplateField>
                <ItemTemplate>
                    <asp:Button ID=btnSelect runat=server OnClick="btnSelect_Click" />
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
           
</Columns>

Protected Sub btnSelect_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim btnSelect As Button = CType(sender, Button)
        Dim row As GridViewRow = CType(btnSelect.NamingContainer, GridViewRow)

       Dim gvIDs As String = ""
       gvIDs += gv.Cells.Item([the data required to redirect]).Text

        Response.Redirect("Page.aspx?str=" & gvIDs)

End Sub

Hope this helps.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:spectre921
ID: 20023438
You previously mentioned a query parameter to send me to the next page.  I think you are right on target with my problem.  I have tried to do that.  I have dug around in books and on the Internet enough that I believe that is the way I should go.  But, I'm just not successful with it.  I now have the hyperlink set up in a column next to each row.  In that hyperlink, I have the id number that needs to be carried to the detail page.  I can click on the hyperlink (id number) and I do get the detail page with the id number showing in the url.  But, I do not get any data pertaining to that id number to display on the detail page.  This data that should be displaying on the detail page is being pulled from a different table that contains the id number from the main page.  I've checked the sql statements and can see that the where clause is inserted referencing the id number from the main table.  I keep looking at the code from the details page and can't see anything wrong with it.  Help!  
0
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 20023838
Are you grabbing the querystring?
Your url should look like this:
yoursite.com/detailpage.aspx?id=passed id
Then your datasource can be set up with a querystring parameter.

<asp:SqlDataSource ID="datasourceid" runat="server" ConnectionString="<%$ ConnectionStrings:dbConnectionString %>"
    SelectCommand="SELECT ItemId, ItemName, ItemDetail  FROM tbl_items WHERE (itemId = @id)">
        <SelectParameters>
           <asp:QueryStringParameter DefaultValue="" Name="id" QueryStringField="id" />
       </SelectParameters>
</asp:SqlDataSource>

To tell you anything beyond thatwould require me to see some of your code.
0
 

Author Comment

by:spectre921
ID: 20024209
My url does look like your example.

I have compared the piece of code that you added to what I have.  It is exactly the same with exception to naming convention.  I still can't see the detail information on the detail page.

Here is a sample of a few pieces of my code:

Here is the url:
http://localhost:2859/FCN/FloatDetail.aspx?id=102934

Here is the hyperlink:
<asp:HyperLinkField HeaderText="XXXCustNo" DataTextField="XXXCustNo" DataNavigateUrlFields="XXXCustNo" DataNavigateUrlFormatString="FloatDetail.aspx?id={0}" >
   <HeaderStyle HorizontalAlign="Center" />

Here is the query parameter:
<asp:SqlDataSource ID="DetailsSqlDataSource" runat="server"
   ConnectionString="<%$ ConnectionStrings:FCNConnectionString %>"
   OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [Client_Assigned_Float] WHERE ([XXXCustNo] = @XXXCustNo)">
   <SelectParameters>
     <asp:QueryStringParameter DefaultValue="" Name="XXXCustNo" QueryStringField="XXXCustNo"
        Type="Int32" />
   </SelectParameters>

I hope this helps...


0
 

Author Comment

by:spectre921
ID: 20024232
I have to leave in 15 minutes and won't be back until Tuesday morning...  If I don't see a response from you by then, I will respond on Tuesday morning...  Thanks in advance for all your help.  I really appreciate it.
0
 

Author Comment

by:spectre921
ID: 20024238
I should also mention that I don't receive any errors when I look at these pages in the browser.  FYI...
0
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 20024380
Since you're using OldValuesParameterFormatString="original_{0}" then your querystring needs to look like this.
...Float] WHERE ([XXXCustNo] = @original_XXXCustNo)">...
That should be the only thing that would need to be changed. Let me know how it turns out.
0
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 20024659
My apologies that would be for an update command. A select command will probably error out. Let me look at this some more over the weekend. I've replicated most of your situation and it seems to work fine on my end.
0
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 2000 total points
ID: 20026428
Ok you have it right except the querystringfield  needs to match the querystring you're passing. So just change     QueryStringField="XXXCustNo"     to read     QueryStringField="id"

Sorry appearently I glanced over that and only realized it after i copied your code into my app.

0
 

Author Comment

by:spectre921
ID: 20042041
Thanks so much.  Changing "XXXCustNo" to "id" worked.  That makes sense too.  I can't believe I overlooked reading the parameter that I have passed.  Sometimes, I have a hard time seeing "the forest through the trees" so to speak.  Thanks again.  I appreciate it.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month15 days, 18 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