Hi Don,
Here is a code sample for you. It uses the SelectedIndexChanged event.
*** The HTML
<asp

ataGrid id="DataGrid1" runat="server">
<Columns>
<asp:ButtonColumn Text="Select"
CommandName="Select"></asp:ButtonColumn>
</Columns>
</asp

ataGrid>
*** The code-behind
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Bind()
End If
End Sub
Private Sub Bind()
Dim Qry1 As System.Data.SqlClient.SqlDataReader
Dim connectionString As String = "server='localhost';
trusted_connection=true; Database='pubs'"
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT au_id, au_lname, au_fname FROM
authors"
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Qry1 =
sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
DataGrid1.DataSource = Qry1
DataGrid1.DataBind()
Qry1.Close()
sqlCommand.Dispose()
sqlConnection.Close()
sqlConnection.Dispose()
End Sub
Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DataGrid1.SelectedIndexChanged
Response.Write(DataGrid1.SelectedIndex & "<br>")
Response.Write(DataGrid1.SelectedItem.Cells(1).Text & "<br>")
Response.Write(DataGrid1.SelectedItem.Cells(2).Text & "<br>")
End Sub
Thank you, Mike
Microsoft, ASP.NET Support Professional
Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer's security.
This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------
From: "Don Hans" <
[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
Subject: find value of cell in datagrid?
Lines: 14
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <
[email protected]>
Date: Thu, 18 Dec 2003 21:59:49 GMT
NNTP-Posting-Host: 68.192.112.82
X-Complaints-To: (e-mail address removed)
X-Trace: news4.srv.hcvlny.cv.net 1071784789 68.192.112.82 (Thu, 18 Dec 2003 16:59:49 EST)
NNTP-Posting-Date: Thu, 18 Dec 2003 16:59:49 EST
Organization: Optimum Online
Path:
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-online.de!newsfeed.icl.net!newsfeed.fjserv.net!newshosting.com!news-xfer2.atl.newshosting.com!38.144.126.100.MISMATCH!feed5.newsreader.com!newsreader.com!news3.optonline.net!news4.srv.hcvlny.cv.net.POSTED!not-for
-mail
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet.webcontrols:16935
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
Gents,
What is the easiest way to get the actual value of a cell in a bound web
datagrid contol? I have a grid bound to a oledb table. I filled and bound
the data, laid out the columns, no problem,
However, I need to get the value of a field (cell?) in the selected row of
the grid. I've tried a bunch of ways, which yeild a value of "nothing", and
have seen references to other methods that seem extremely complicated.
Isn't there just a simple way to reference the value of a cell in a grid?