find value of cell in datagrid?

Discussion in 'ASP .Net Web Controls' started by Don Hans, Dec 18, 2003.

  1. Don Hans

    Don Hans Guest

    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?
     
    Don Hans, Dec 18, 2003
    #1
    1. Advertising

  2. Hi Don,

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

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

    *** 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" <>
    > 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: <prpEb.276089$>
    > Date: Thu, 18 Dec 2003 21:59:49 GMT
    > NNTP-Posting-Host: 68.192.112.82
    > X-Complaints-To:
    > 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.su
    l.t-online.de!t-online.de!newsfeed.icl.net!newsfeed.fjserv.net!newshosting.c
    om!news-xfer2.atl.newshosting.com!38.144.126.100.MISMATCH!feed5.newsreader.c
    om!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?
    >
    >
    >
    >
     
    Mike Moore [MSFT], Dec 19, 2003
    #2
    1. Advertising

  3. Don Hans

    Don Hans Guest

    Perfect, thanks for the help!

    ""Mike Moore [MSFT]"" <> wrote in message
    news:...
    > Hi Don,
    >
    > Here is a code sample for you. It uses the SelectedIndexChanged event.
    >
    > *** The HTML
    > <asp:DataGrid id="DataGrid1" runat="server">
    > <Columns>
    > <asp:ButtonColumn Text="Select"
    > CommandName="Select"></asp:ButtonColumn>
    > </Columns>
    > </asp:DataGrid>
    >
    > *** 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" <>
    > > 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: <prpEb.276089$>
    > > Date: Thu, 18 Dec 2003 21:59:49 GMT
    > > NNTP-Posting-Host: 68.192.112.82
    > > X-Complaints-To:
    > > 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.su
    >

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

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

    om!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?
    > >
    > >
    > >
    > >

    >
     
    Don Hans, Dec 19, 2003
    #3
  4. 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" <>
    > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > References: <prpEb.276089$>

    <>
    > 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$>
    > Date: Fri, 19 Dec 2003 04:23:43 GMT
    > NNTP-Posting-Host: 68.192.112.82
    > X-Complaints-To:
    > 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!cpmsftngxa09.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!ne
    ws3.optonline.net!news4.srv.hcvlny.cv.net.POSTED!not-for-mail
    > Xref: cpmsftngxa07.phx.gbl

    microsoft.public.dotnet.framework.aspnet.webcontrols:16944
    > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    >
    > Perfect, thanks for the help!
    >
    > ""Mike Moore [MSFT]"" <> wrote in message
    > news:...
    > > Hi Don,
    > >
    > > Here is a code sample for you. It uses the SelectedIndexChanged event.
    > >
    > > *** The HTML
    > > <asp:DataGrid id="DataGrid1" runat="server">
    > > <Columns>
    > > <asp:ButtonColumn Text="Select"
    > > CommandName="Select"></asp:ButtonColumn>
    > > </Columns>
    > > </asp:DataGrid>
    > >
    > > *** 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" <>
    > > > 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: <prpEb.276089$>
    > > > Date: Thu, 18 Dec 2003 21:59:49 GMT
    > > > NNTP-Posting-Host: 68.192.112.82
    > > > X-Complaints-To:
    > > > 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.su
    > >

    >

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

    >

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

    >

    om!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?
    > > >
    > > >
    > > >
    > > >

    > >

    >
    >
    >
     
    Mike Moore [MSFT], Dec 19, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmVmZg==?=

    Find the value of a read only datagrid cell

    =?Utf-8?B?SmVmZg==?=, Nov 29, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    6,279
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Nov 29, 2005
  2. Bernard O'Flynn

    How do you find out the value of a cell in another row?

    Bernard O'Flynn, Sep 17, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    119
    Bernard O'Flynn
    Sep 17, 2003
  3. Empire City
    Replies:
    3
    Views:
    414
    Empire City
    Apr 30, 2004
  4. RJ
    Replies:
    1
    Views:
    244
    Eliyahu Goldin
    Feb 17, 2005
  5. Don Hans

    find datagrid item cell by ID (name)

    Don Hans, Dec 20, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    125
    Don Hans
    Dec 20, 2003
Loading...

Share This Page