• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1349
  • Last Modified:

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()
0
sny23vpb
Asked:
sny23vpb
1 Solution
 
informaniacCommented:
Try this...

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

This will give the cell that sent the postback
0
 
sny23vpbAuthor Commented:
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}
0
 
Bob LearnedCommented:
How is the Button defined in the GridView HTML?  Did you define a CommandName for the Button.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
sny23vpbAuthor Commented:
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
0
 
RamuncikasCommented:
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
0
 
RamuncikasCommented:
:) sorry, will put in Code snippet.
<asp:TemplateField>
	<ItemTemplate>
		<a href="custedit.aspx?id=<% Eval("CustIDFieldName") %>Edit</a>" />
	</ItemTemplate>
</asp:TemplateField>

Open in new window

0
 
sny23vpbAuthor Commented:
Thank you !
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now