DataGrid, DataView, & VWD.
Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=15209
Printed Date: 29 March 2026 at 4:25am Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com
Topic: DataGrid, DataView, & VWD.
Posted By: davidshq
Subject: DataGrid, DataView, & VWD.
Date Posted: 24 May 2005 at 3:27pm
Okay, I'm trying this whole new .NET 2.0 thing and the beta Visual Web
Developer Express. Its pretty cool. It does a lot of the coding
automatically (especially the boring redundant stuff) but that doesn't
mean that I still don't manage to get myself into trouble.
Now, here's my current project:
- Create a program that reads from a database a list of games and
displays them on the screen. Allows any one of these to be selected and
once selected upons up a fuller description of the game.
The first part - displaying a list of games and making them selectable
is easy, a SqlDataConnection and DataGrid using VWD and I'm up and
running in five mins. The problem arises in that I now have
default.aspx that hosts the DataGrid and showgame.aspx that hosts the
DataView. The idea is for the SelectedIndexChanged event to trigger a
redirection from default to showgame using a querystring. However, I
don't know how to get the ID from the selected row (its not one of the
items I want visually displayed) and once I get it I'm not quite sure
how to pass it to the DataView. If anyone can help me get the ID I
think I can figure out connecting it to the DataView.
Here is my current code in the SelectedIndexChanged event (which doesn't work):
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Dim url As String
Dim ID As GridViewRow = GridView1.ID
url = "showgame.aspx?ID=" + ID
Response.Redirect(url)
End Sub
David.
------------- - http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.
|
Replies:
Posted By: Mart
Date Posted: 24 May 2005 at 4:03pm
try
Dim ID As GridViewRow = GridView1.SelectedRow
or
Dim ID As GridViewRow = GridView1.Items(GridView1.SelectedIndex)
or something similar to that
|
Posted By: davidshq
Date Posted: 25 May 2005 at 10:46am
Thanks Mart. I'm closer than before. But I'm not getting another error. Here is the code:
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Dim url
Dim ID As GridViewRow = GridView1.SelectedRow
url = "showgame.aspx?ID=" + ID
Response.Redirect(url)
End Sub
It throws an error saying that the Operator + is not
defined for types 'String' and 'System.Web.UI.WebControls.GridViewRow'.
If I click the select button without the +ID part it goes
to the new page, but without the DataView knowing which ID to go to it
just ends up at the first one. :-/
David.
------------- - http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.
|
Posted By: davidshq
Date Posted: 25 May 2005 at 11:46am
Okay...I've made some progress since my last post. Here is the new code that works:
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Dim row As GridViewRow = GridView1.SelectedRow
Dim ID As String
ID = row.Cells(2).Text
Dim url As String
' Dim ID As GridViewRow = GridView1.SelectedRow
url = "showgame.aspx?ID=" + ID
Response.Redirect(url)
End Sub
The only remaining problem is that I prefer that the ID not be visible. So I tried the following code:
Protected Sub GridView1_SelectedIndexChanging(ByVal sender As Object, ByVal e As GridViewSelectEventArgs)
Dim row As GridViewRow = GridView1.SelectedRow
row.Cells(2).Visible = True
End Sub
What I am trying to do here is take the formerly
invisible ID column and make it visible, then in the SelectIndexChanged
event I use that ID to send to the next page. The problem is that for
some reason it is not making the row visible in time (its not passing
it before the code in SelectedIndexChanged) and so there is no ID
variable.
David.
------------- - http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.
|
Posted By: Mart
Date Posted: 25 May 2005 at 12:06pm
If you set the GridViews Key to the ID field and don't add a column for it then just use:
Dim ID As String = GridView1.Keys(GridView1.SelectedRow.Index)
|
|