Results 1 to 3 of 3

Thread: How can I capture DataGrid Cell value?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Windsor
    Posts
    100

    How can I capture DataGrid Cell value?

    Hi,

    I have a DataGrid and there is a Delete button. When I press the Delete button, I want to capture 4th cell value from the data grid and use it, but no value is returned. What do you think my problem?

    Button is defined as:
    <asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>


    Private Sub dgConsultants_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgConsultants.ItemCommand

    Dim item As String = e.Item.Cells(4).Text

    End Sub

  2. #2
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    loop through and find the control as
    If e.Item.Cells(4).Controls(index).GetType = Then..... System.Web.UI.WebControls.LinlButton???
    e.Item.Cells(4).Controls(index).Text

    I have never done this or I would give a better example
    Magiaus

    If I helped give me some points.

  3. #3
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    First, make sure the ItemCommand event is actually firing.

    Write a simple string to the page to test:
    Code:
    Private Sub dgConsultants_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgConsultants.ItemCommand
    
        Response.Write("ItemCommand")
    
    End Sub
    If that is working then loop through all the cells printing them out:
    Code:
    Private Sub dgConsultants_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgConsultants.ItemCommand
    
            For i As Integer = 0 To e.Item.Cells.Count - 1
                Response.Write("Cell " + i.ToString() + " = " + e.Item.Cells(i).Text + "<BR>")
            Next
    
    End Sub
    Then you know what cell index you need.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width