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
543 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
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

838 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