I have a question about GridView. In my code, I have a HyperLinkField like below:
<asp:HyperLinkField Dat开发者_JAVA百科aTextField="DocumentAlbum.Name" HeaderText="Nama Album" SortExpression="Album"
DataNavigateUrlFields="AlbumID" DataNavigateUrlFormatString="~/Extras/UploadFile.aspx?DocumentAlbumID={0}" Target="_blank" />
Everything works fine except for 1 thing. If you see from the picture, Document has a relation with DocumentAlbum where Document's AlbumID is taken from DocumentAlbum's ID. My goal is to show DocumentAlbum's name in the HyperLinkFieled. That is why I use DataTextField="DocumentAlbum.Name"
instead of DataTextField="AlbumID"
. Apparently, this does not work.
Do you guys know how can I retrieve the album's name instead of ID?
Thank you soooooooooo much in advance. This problem has been bugging me for a while.
If you do a SQL JOIN condition between Document and DocumentAlbum, you can bring back the album name in the query that is assigned to the GridView. Then I believe you can add the album name as a column to the GridView but set the column visibility to false (it's been a while with me working with the GridView so I don't remember if you have to include the column to reference it like you're doing). Then you should be able to do DataTextField="Name".
精彩评论