Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - DataGrid, DataView, & VWD.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

DataGrid, DataView, & VWD.

 Post Reply Post Reply
Author
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post Topic: DataGrid, DataView, & VWD.
    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.
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post 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)
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.