Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 568
  • Last Modified:

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

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
panasonic2012
Asked:
panasonic2012
  • 5
  • 4
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
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
 
panasonic2012Author Commented:
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
 
Meir RivkinFull stack Software EngineerCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Meir RivkinFull stack Software EngineerCommented:
<SCRIPT type="text/javascript"> 
function openWindow(...){

}
</SCRIPT>

Open in new window

0
 
panasonic2012Author Commented:
these are not working :(
0
 
panasonic2012Author Commented:
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
 
Meir RivkinFull stack Software EngineerCommented:
so u wanna redirect to CandidateProfile.aspx only if user click on specific column?
0
 
panasonic2012Author Commented:
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
 
panasonic2012Author Commented:
figured it out
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now