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
527 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
  • 5
  • 4
9 Comments
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 42

Expert Comment

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

}
</SCRIPT>

Open in new window

0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:panasonic2012
Comment Utility
these are not working :(
0
 

Author Comment

by:panasonic2012
Comment Utility
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
Comment Utility
so u wanna redirect to CandidateProfile.aspx only if user click on specific column?
0
 

Accepted Solution

by:
panasonic2012 earned 0 total points
Comment Utility
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
Comment Utility
figured it out
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

14 Experts available now in Live!

Get 1:1 Help Now