We help IT Professionals succeed at work.

Use select button in gridview to move to a new page

spectre921
spectre921 asked
on
228 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?
Comment
Watch Question

Dustin HopkinsSenior Web Developer
CERTIFIED EXPERT

Commented:
Without being too particular could you not use a hyperlink column to send querystring parameters to the other page?
Dustin HopkinsSenior Web Developer
CERTIFIED EXPERT

Commented:
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.
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.

Author

Commented:
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!  
Dustin HopkinsSenior Web Developer
CERTIFIED EXPERT

Commented:
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.

Author

Commented:
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...


Author

Commented:
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.

Author

Commented:
I should also mention that I don't receive any errors when I look at these pages in the browser.  FYI...
Dustin HopkinsSenior Web Developer
CERTIFIED EXPERT

Commented:
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.
Dustin HopkinsSenior Web Developer
CERTIFIED EXPERT

Commented:
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.
Senior Web Developer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
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.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.