Solved

Select in Gridview with postbackurl

Posted on 2008-06-20
5
936 Views
Last Modified: 2008-06-24
I have a gridview in my form. My goal is to allow users to select a record and:

1 - have in write a session variable.
2 - Postback to a 2nd page .
3 - When the user closes out of the 2nd page, have the record that was selected highlighted.

When I enable select in my gridview  I can do 1 & 3, but not 2.
When I have a hyperlink I can do 2, but not 1&3.

How can I accomplish all three goals with one click?
0
Comment
Question by:billkrieger
  • 3
  • 2
5 Comments
 
LVL 22

Expert Comment

by:prairiedog
ID: 21831789
>>>When the user closes out of the 2nd page, have the record that was selected highlighted.
Is the 2nd page a pop-up?
0
 

Author Comment

by:billkrieger
ID: 21832087
No, it is not a pop up page. In my datagrid I have a record set that is reading from a stored procedure that is pulling from different tables. When the user selects a record in the datagrid, I am assigning the recordID (related field) as a session variable. The second page is a frame page that has three frames that will pull data matching the session variable.

Currently I have the select button enabled in my gridview which sets my session variable on selectedindexchange and the selected Item gets highlighted. I have a button that will postbackurl to the framed page on click. The framed page opens fine, and when the browsers back button is clicked the user goes back to the original page and the selected item is still highlighted in my gridview.

I would like to eliminate the process of having to click the button after selecting a record. I would like the framed page to open when the user clicks on select in the datagrid.

I changed my gridview to have a hyperlink. This opened my frame page, but did not set my session variable.

Thanks for your help!
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 500 total points
ID: 21835206
In GridView's RowDataBound event handler, you can do this:
Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If (e.Row.RowType = DataControlRowType.DataRow) Then
            If (Session("RowIndex") IsNot Nothing) Then
                If (e.Row.RowIndex = Int32.Parse(Session("RowIndex").ToString())) Then
                    e.Row.BackColor = Drawing.Color.Yellow    <====change to whatever color you want
                End If
            End If
        End If
    End Sub

But this is not going to work if user clicks browser's Back button. What you can do is to put a link on the 2nd page to redirect user back to the 1st page.
0
 

Author Comment

by:billkrieger
ID: 21857740
Thanks, I will give it a try. on a page with three frames, how do put a link that will close out of all frames and open the 1st page?
0
 

Author Comment

by:billkrieger
ID: 21858085
ok. not sure what I was thinking. the simple way to do what I was looking for was to
Response.Redirect after setting my session variables and code on the selectedindexchange. Thanks for your help.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 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