Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > find value of cell in datagrid?

Reply
Thread Tools

find value of cell in datagrid?

 
 
Don Hans
Guest
Posts: n/a
 
      12-18-2003
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?



 
Reply With Quote
 
 
 
 
Mike Moore [MSFT]
Guest
Posts: n/a
 
      12-19-2003
Hi Don,

Here is a code sample for you. It uses the SelectedIndexChanged event.

*** The HTML
<aspataGrid id="DataGrid1" runat="server">
<Columns>
<asp:ButtonColumn Text="Select"
CommandName="Select"></asp:ButtonColumn>
</Columns>
</aspataGrid>

*** 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(connectionStri ng)
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.CommandBehavi or.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).Tex t & "<br>")
Response.Write(DataGrid1.SelectedItem.Cells(2).Tex t & "<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" <(E-Mail Removed)>
> Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontro ls
> 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: <prpEb.276089$(E-Mail Removed) >
> Date: Thu, 18 Dec 2003 21:59:49 GMT
> NNTP-Posting-Host: 68.192.112.82
> X-Complaints-To: http://www.velocityreviews.com/forums/(E-Mail 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!TK2MSFTN GP08.phx.gbl!newsfeed00.su
l.t-online.de!t-online.de!newsfeed.icl.net!newsfeed.fjserv.net!new shosting.c
om!news-xfer2.atl.newshosting.com!38.144.126.100.MISMATCH! feed5.newsreader.c
om!newsreader.com!news3.optonline.net!news4.srv.hc vlny.cv.net.POSTED!not-for
-mail
> Xref: cpmsftngxa07.phx.gbl

microsoft.public.dotnet.framework.aspnet.webcontro ls:16935
> X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontro ls
>
> 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?
>
>
>
>


 
Reply With Quote
 
 
 
 
Don Hans
Guest
Posts: n/a
 
      12-19-2003
Perfect, thanks for the help!

""Mike Moore [MSFT]"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Don,
>
> Here is a code sample for you. It uses the SelectedIndexChanged event.
>
> *** The HTML
> <aspataGrid id="DataGrid1" runat="server">
> <Columns>
> <asp:ButtonColumn Text="Select"
> CommandName="Select"></asp:ButtonColumn>
> </Columns>
> </aspataGrid>
>
> *** 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(connectionStri ng)
> 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.CommandBehavi or.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).Tex t & "<br>")
> Response.Write(DataGrid1.SelectedItem.Cells(2).Tex t & "<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" <(E-Mail Removed)>
> > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontro ls
> > 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: <prpEb.276089$(E-Mail Removed) >
> > Date: Thu, 18 Dec 2003 21:59:49 GMT
> > NNTP-Posting-Host: 68.192.112.82
> > X-Complaints-To: (E-Mail 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!TK2MSFTN GP08.phx.gbl!newsfeed00.su
>

l.t-online.de!t-online.de!newsfeed.icl.net!newsfeed.fjserv.net!new shosting.c
>

om!news-xfer2.atl.newshosting.com!38.144.126.100.MISMATCH! feed5.newsreader.c
>

om!newsreader.com!news3.optonline.net!news4.srv.hc vlny.cv.net.POSTED!not-for
> -mail
> > Xref: cpmsftngxa07.phx.gbl

> microsoft.public.dotnet.framework.aspnet.webcontro ls:16935
> > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontro ls
> >
> > 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?
> >
> >
> >
> >

>



 
Reply With Quote
 
Mike Moore [MSFT]
Guest
Posts: n/a
 
      12-19-2003
Hi Don,

I'm glad it helped you.

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" <(E-Mail Removed)>
> Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontro ls
> References: <prpEb.276089$(E-Mail Removed) >

<(E-Mail Removed)>
> Subject: Re: find value of cell in datagrid?
> Lines: 119
> 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: <j3vEb.284411$(E-Mail Removed) >
> Date: Fri, 19 Dec 2003 04:23:43 GMT
> NNTP-Posting-Host: 68.192.112.82
> X-Complaints-To: (E-Mail Removed)
> X-Trace: news4.srv.hcvlny.cv.net 1071807823 68.192.112.82 (Thu, 18 Dec

2003 23:23:43 EST)
> NNTP-Posting-Date: Thu, 18 Dec 2003 23:23:43 EST
> Organization: Optimum Online
> Path:

cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!cpmsftng xa09.phx.gbl!TK2MSFTNGP08.
phx.gbl!newsfeed00.sul.t-online.de!t-online.de!tiscali!newsfeed1.ip.tiscali.
net!newshosting.com!news-xfer1.atl.newshosting.com!167.206.3.103.MISMATCH!n e
ws3.optonline.net!news4.srv.hcvlny.cv.net.POSTED!n ot-for-mail
> Xref: cpmsftngxa07.phx.gbl

microsoft.public.dotnet.framework.aspnet.webcontro ls:16944
> X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontro ls
>
> Perfect, thanks for the help!
>
> ""Mike Moore [MSFT]"" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi Don,
> >
> > Here is a code sample for you. It uses the SelectedIndexChanged event.
> >
> > *** The HTML
> > <aspataGrid id="DataGrid1" runat="server">
> > <Columns>
> > <asp:ButtonColumn Text="Select"
> > CommandName="Select"></asp:ButtonColumn>
> > </Columns>
> > </aspataGrid>
> >
> > *** 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(connectionStri ng)
> > 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.CommandBehavi or.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).Tex t & "<br>")
> > Response.Write(DataGrid1.SelectedItem.Cells(2).Tex t & "<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" <(E-Mail Removed)>
> > > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontro ls
> > > 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: <prpEb.276089$(E-Mail Removed) >
> > > Date: Thu, 18 Dec 2003 21:59:49 GMT
> > > NNTP-Posting-Host: 68.192.112.82
> > > X-Complaints-To: (E-Mail 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!TK2MSFTN GP08.phx.gbl!newsfeed00.su
> >

>

l.t-online.de!t-online.de!newsfeed.icl.net!newsfeed.fjserv.net!new shosting.c
> >

>

om!news-xfer2.atl.newshosting.com!38.144.126.100.MISMATCH! feed5.newsreader.c
> >

>

om!newsreader.com!news3.optonline.net!news4.srv.hc vlny.cv.net.POSTED!not-for
> > -mail
> > > Xref: cpmsftngxa07.phx.gbl

> > microsoft.public.dotnet.framework.aspnet.webcontro ls:16935
> > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontro ls
> > >
> > > 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?
> > >
> > >
> > >
> > >

> >

>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find the value of a read only datagrid cell =?Utf-8?B?SmVmZg==?= ASP .Net 3 11-29-2005 07:49 PM
How to set cell background based on cell value when datagrid is displayed RJ ASP .Net Datagrid Control 1 02-17-2005 09:37 PM
RadioButtonList In A DataGrid Cell - Can I find the selected button without editing the cell? Empire City ASP .Net Datagrid Control 3 04-30-2004 12:19 AM
How do you find out the value of a cell in another row? Bernard O'Flynn ASP .Net Datagrid Control 0 09-17-2003 04:37 PM
moving to cell Y if cell X has value Z. Clarke Rice Computer Support 0 06-30-2003 09:35 AM



Advertisments