Solved

Selected Value Gridview Row Command

Posted on 2008-10-19
8
1,343 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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 300 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

624 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