Obtaining Cell value of Datagrid using Select Button on the SelectedIndexChanged Event

Posted on 2006-04-28
Last Modified: 2008-02-01
I have a datagrid that I want an event to fire when user hits the select button.  I have put a select button on the datagrid and then put some code in the SelectedIndexChanged event handler for that datagird.   All i am trying to do is get the keyfield value from the selected item of the datagrid.   e arg has no elements to reference cell or control values in the selected row of the data grid.   I therefore am trying the following code to try to get at the value of this keyfield.   The Keyfield is on the first cell (0).   and here is what I am to do.  I want to assign the variable "fileID" to the value of the selected row item so I can use that to pass to by SQL command.

    Private Sub DataGrid2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid2.SelectedIndexChanged
        Dim fileID As Integer
        fileID = Me.DataGrid2.SelectedItem.Cells(0).FindControl(0)????????
    End Sub

I have taken two approches.  One was to access the cell value directly.  The other was to convert that column on the datagrid to a template and put the value in a label  "lblFileID"

Since the e arg give very little to work with on this handler, what would be the best way to handle this situation.

Question by:jholmes724
    LVL 6

    Accepted Solution

    Try this:
    fileID = Me.DataGrid2.SelectedItem.Cells(0).Text

    Author Comment

    Thanks that work.  I forgot I had changed it to a templat column.  Once I changed it back to a normal column your code line work.  Thank you.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now