Solved

How can I use the RowDataBound declaration on a GridView to navigate away to new .aspx page with Specific window size

Posted on 2012-12-25
9
549 Views
Last Modified: 2012-12-30
i use a following code in rowdatabound event

if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onClick"] = string.Format("window.location = 'CandidateProfile.aspx?candidateID={0}';", DataBinder.Eval(e.Row.DataItem, "candidateID"))

}

i want to change it so the click event opens in a new window with specified height and width

how can i do that , plz help
0
Comment
Question by:panasonic2012
[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
  • 5
  • 4
9 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 38720134
something like:

var url = string.Format('CandidateProfile.aspx?candidateID={0}';", DataBinder.Eval(e.Row.DataItem, "candidateID"));

ClientScript.RegisterStartupScript(this.GetType(), "openWindow",
 "<script>openWindow('url')</script>");

function openWindow(url, redirectUrl) {
    var x = window.open(url, 'mynewwin', '_blank', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=520,modal=yes,alwaysRaised=yes');
    x.focus();
    window.location = redirectUrl;
}

Open in new window


or calling Response.Redirect:

Response.Redirect(string.Format("CandidateProfile.aspx?candidateID={0}';", DataBinder.Eval(e.Row.DataItem, "candidateID")", "_blank", "menubar=0,scrollbars=1,width=780,height=900,top=10");

Open in new window



change the width/height according to your needs.



cheers
0
 

Author Comment

by:panasonic2012
ID: 38720177
is this the server side code ?

do i write the frist code in e.Row.Attributes["onClick"] = .. ?

is the last function openWindow has to be written on aspx ?

plz explain

sorry im new
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38720282
In your aspx add script tag and code the function inside.
So upon row click, the function is being called passing the url with relevant data.
I wasnt infront of a pc but this is the idea.
U can try response.redirect but im not its gonna work, i havent tested it yet
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 42

Expert Comment

by:sedgwick
ID: 38720284
<SCRIPT type="text/javascript"> 
function openWindow(...){

}
</SCRIPT>

Open in new window

0
 

Author Comment

by:panasonic2012
ID: 38720764
these are not working :(
0
 

Author Comment

by:panasonic2012
ID: 38720782
i tried this
e.Row.Attributes.Add("onclick", "javascript:window.open('CandidateProfile.aspx?candidateID=" + DataBinder.Eval(e.Row.DataItem, "candidateID") + "',null,'left=162px, top=134px, width=500px, height=500px, status=no, resizable= yes, scrollbars=yes, toolbar=no, location=no, menubar=no');");

it works but i dont want the click event in the last column of the grid as it has button in that column
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38720788
so u wanna redirect to CandidateProfile.aspx only if user click on specific column?
0
 

Accepted Solution

by:
panasonic2012 earned 0 total points
ID: 38720793
never mind i got it

 if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState == DataControlRowState.Alternate)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                          for (x=0; x < cellCount-1; x++ )
                        e.Row.Cells[x].Attributes.Add("onclick", "javascript:window.open('CandidateProfile.aspx?candidateID=" + DataBinder.Eval(e.Row.DataItem, "candidateID") + "',null,'left=162px, top=134px, width=500px, height=500px, status=no, resizable= yes, scrollbars=yes, toolbar=no, location=no, menubar=no');");
                }
            }
0
 

Author Closing Comment

by:panasonic2012
ID: 38730578
figured it out
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

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…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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