14 Oct 2011

ASP.NET - Transfer to another page using gridview based on 'id'

This is for when you have a GridView with a link based on 'id'.

SQL table (tblMovies): movieID, Title, Year etc.

Page1.aspx

GridView settings
Propeties | Data | DataKeyNames : movieID

GridView tasks
GridView Tasks | Edit Columns | Add HyperLinkField

Add a HyperLinkField

HyperLinkField propeties
Appearance | HeaderText: Blahblah-whatever
Data | DataNavigateUrlFields : movieID
Data | DataNavigateUrlFormatString: ~/Page2.aspx?movieID={0}
Data | DataTextField: movieID

Page2.aspx

In the SqlDataSource you need to use a parameter for the 'id':
Parameter source: 'QueryString'
QueryStringField: movID

SELECT * FROM tblMovies WHERE (tblMovies.movieID = @movID)

This is just a help, not a guide

No comments:

Post a Comment