Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clicking on a DataGrid Row 1

Status
Not open for further replies.

acent

Technical User
Feb 17, 2006
247
US
Hello All,

This is to build off thread855-1425404. What I want is the simplest way to be able to click on a datagrid and go to another page based on the row clicked. I am a noob so please be patient with me.

I am using VB/ASP.NET 1.1 (moving to 2.0 this Friday night). The aforementioned thread is C#, and while i have nothing against C#, at all costs I do not want to mix C# code with my VB app. I would consider that bad programming.

I have this:
Code:
  Private Sub get_users()
    Dim conn as New OleDbConnection(ConfigurationSettings.AppSettings("accdb"))
    
    Const strSQL as String = "SELECT user_rowid AS ID, fname AS [First Name] FROM qryUsers"
    Dim sqlCMD as New OleDbCommand(strSQL, conn)
    
    conn.Open()
    dgUsers.DataSource = sqlCMD.ExecuteReader(CommandBehavior.CloseConnection)
    dgUsers.DataBind()
    conn.Close
  End Sub

And as we all know, this gives me the most basic plain jane table ever.
Code:
<table cellspacing="0" rules="all" border="1" id="dgUsers">
  <tr>
    <td>ID</td><td>First Name</td>
  </tr><tr>
    <td>uid1</td><td>uname1</td>
  ...
</table>

I'll put lipstick on the pig later. What I want is to this:
Code:
<table cellspacing="0" rules="all" border="1" id="dgUsers">
  <tr>
    <td>First Name</td>
  </tr><tr>
    <td><a href="page2.aspx?=uid1">uname1</a></td>
  ...
</table>
I have googled on this. Surfed some threads, but nothing exactly fits for VB. The closest thing I've found requires new sub routines and 20some lines of code. Only to leave me thinking... "this can't be THAT hard".

Not to sound like a blues singer, but this concept is easy in ASP, PHP, JSP, and ColdFusion; .NET seems to be another animal.

Many thanks for the help.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
Do you want to use the gridview control, or just a simple table? If you are not Inserting, Updating, or Deleting data, then you should not use a grid.
 
Thanks for the post jbenson001,

Didn't think of a GridView. A brief perusal of MSDN suggests that the GridView will build the same table just as easily. This page is just displaying data.

Here's a shot in the dark for how my code might change.
Code:
    conn.Open()
    gvUsers.DataSource = sqlCMD.ExecuteReader(CommandBehavior.CloseConnection)
    gvUsers.DataBind()
    gvUsers.Columns.Add('First Name')
    gvUsers.HyperLinkField('ID')
    conn.Close
  End Sub

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
If you are just displaying data, with links, then use a repeater. This way you can easily customize the HTML, use binding, and loose the overhead of a gridview that is NOT needed in your case.
 
OK. The plot thickens. I'm not stuck on using any specific control. If I can skip some overhead then all the better!

What is the difference then between the DataGrid, GridView, and Repeaters (other than overhead), and when is a good use for the options?

Thank you very much for the help.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
Datagrid is the older grid from 1.0, 1.0, in 2.0 and up it is called the GridView. They should only be used when you need to Insert, Update or Delete data.

for your purposes of only diplaying data, then simply use a repeater. It is bindable and you can customize the HTML. It is difficult to customize the HTML when using a Grid.
 
So then the DataGrid/GridView would be used to display the same HTML table, but would probably be best used to display a table of, say, textboxes, where the user could modify and then submit back the table for updating of the database? Or something of this nature?

I'm kind of hijacking my own thread here, but as stated above, I am learning.

Thanks.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top