Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 4th, 2014, 03:39 AM
Registered User
 
Join Date: Dec 2013
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Default Assigning a GridView control an incoming ID

Hello,

I have a Contacts.aspx page that contains a SQLDataSource and a GridView control. The Contact_ID column in the GridView contains the following information in the hyperlink.

<a... NavigateUrl='<%# "~/Management/Forms/ContactEdit.aspx?ContactID=" & Eval("Contact ID") %>'.

This works fine and when the hyperlink is clicked, it sends the user to the ContactEdit.aspx page which has a SQLDataSource and a DetailsView control. on the ContactEdit.aspx.vb page I have the following code to catch the incoming id value (the variable intContactID is declared above the Page_Load sub).

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Request.QueryString("ContactID") Is Nothing Or Request.QueryString("ContactID") = 0 Then
'Set detailsview into insert mode
ElseIf IsNumeric(Request.QueryString("ContactID")) Then
'Capture the incoming ContactId value
intContactID = Request.QueryString("ContactID")
Else
'Set to the DetailView to the first record in read mode
End If
End Sub
End Class

I still have code to write for the different scenarios but normally the ContactEdit.aspx page will be called with a valid contactid.

What I want to do is have the user browse the many contact records in the GridView (Contact.aspx) and if they want to edit a record they click on the Contact ID hyperlink associated with the particular record. Clicking the hyperlink will open the ContactEdit.aspx page which will have the record they had selected in the DetailsView control. What I haven't been able to figure out is how to open the DetailsView control with the ID that is being passed to the ContactEdit page. I know that I've captured the ID correctly because I can do a response.write(intContactID) on the page and it displays the contactid that I had sent from the previous page, but I don't know how to use the intContactID variable value to make it the record that is "loaded" or selected in the DetailsView control.

Any help would be greatly appreciated, thank you very much.
 
Old January 4th, 2014, 08:28 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Check out Chapter 13, page 480 and onwards. It shows how yo use a DetailsViiew to edit records using a file called AddEditReview.aspx.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
pmarti (January 4th, 2014)
 
Old January 4th, 2014, 01:30 PM
Registered User
 
Join Date: Dec 2013
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Default Assigning a GridView control an incoming ID

Hi Imar,

Thank you so much, that's exactly what I needed. The two pages are now working together as I hoped. I really appreciate your help.





Similar Threads
Thread Thread Starter Forum Replies Last Post
ID property of a control type cannot be applied through a control skin leemark2k3 BOOK: Beginning ASP.NET 4 : in C# and VB 1 October 23rd, 2013 03:57 PM
How to put a button control in a GridView control ryan.webb ASP.NET 2.0 Basics 2 December 28th, 2007 05:26 AM
Get the Id of Control in ASP rekha_jsr Classic ASP Professional 2 June 14th, 2006 07:37 AM
Assigning DataSet To Custom Server Control Raz Muhammad General .NET 0 November 29th, 2004 01:03 AM
assigning value to file control [email protected] Classic ASP Basics 0 February 24th, 2004 01:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.