Link to home
Start Free TrialLog in
Avatar of sny23vpb
sny23vpb

asked on

Selected Value Gridview Row Command

Is there someway to perform this type of function to determine which value was selected when a user clicks on a button that runs the row command ?

It keeps telling me that I need to create a new instance of that object.

Thanks for any help

 Session("CustID") = GridView2.SelectedValue.ToString()
Avatar of Obadiah Christopher
Obadiah Christopher
Flag of India image

Try this...

((Button)(e.CommandSource)).Parent

This will give the cell that sent the postback
Avatar of sny23vpb
sny23vpb

ASKER

Thank you; but when I use this code ? e.CommandSource.parent returns the System.web information below rather than the Index of the Cell which called the command.

Any other thoughts ?
Thanks

? e.CommandSource.parent  RETURNS:
{System.Web.UI.HtmlControls.HtmlForm}
    System.Web.UI.HtmlControls.HtmlForm: {System.Web.UI.HtmlControls.HtmlForm}
How is the Button defined in the GridView HTML?  Did you define a CommandName for the Button.
I added a new 'button field' to the grid and called it Edit with a  command name 'EditCustomer'
Unfortunately I can't use the grid built in edit functionality for this project; I need to open a separate form with many more fields to allow the user to edit - so I need that customer number or row ID when they click the edit button so that when the next form opens with the code below; it knows which customer to bring into the edit screen.


Thanks for any help.


 Protected Sub GridView2_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView2.RowCommand
         If e.CommandName = "EditCustomer" Then
            Response.Redirect("CustEdit.aspx")
        End If
    End Sub
Add a template field to a grid.

      
            Edit" />
      


This will give you Edit link in a column in each row. This link will redirect user to custedit.aspx page with customer ID in a query string.

R
ASKER CERTIFIED SOLUTION
Avatar of Ramuncikas
Ramuncikas
Flag of Lithuania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you !