Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Selected Value Gridview Row Command

Posted on 2008-10-19
8
Medium Priority
?
1,347 Views
Last Modified: 2012-06-27
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
Comment
Question by:sny23vpb
8 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 22755128
Try this...

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

This will give the cell that sent the postback
0
 

Author Comment

by:sny23vpb
ID: 22782465
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22796093
How is the Button defined in the GridView HTML?  Did you define a CommandName for the Button.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sny23vpb
ID: 22798245
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
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 22798977
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
 
LVL 14

Accepted Solution

by:
Ramuncikas earned 1200 total points
ID: 22798992
:) 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
 

Author Closing Comment

by:sny23vpb
ID: 31507708
Thank you !
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

916 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