Solved

Selected Value Gridview Row Command

Posted on 2008-10-19
8
1,328 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now