I'm using Url Rewriting in my website.
I'm able to rewrite the url using
Response.RedirectToRoute("bills-show");
But from my GridView how can I redirect to another page ?? Currently I'm using the following code in my GridViewRowDataBound
.
e.Row.Attributes.Add("onclick", "location='CallCenter/BillDetails.aspx?billNo=" + e.Row.Cells[0].Text + "'");
But what I need is using URL Rewriting.
I tried using
e.Row.Attributes.Add("onclick", "WriteUrl(" + e.Row.Cells[0].Text + ")"); // in GridViewRowDataBound.
and
protected string WriteUrl(string billNo)
{
return pg.GetRouteUrl("bill-details", new { billno = billNo });
}
but this is not working !!!
Can you help me out ???
Use HyperLinkField in GridView columns list:
<asp:HyperLinkField HeaderText="Account" DataTextField="Account"
DataNavigateUrlFields="Account" Target="_blank"
DataNavigateUrlFormatString="CallCenter/BillDetails.aspx?billNo=n={0}"
SortExpression="Account" HeaderStyle-Width="61" />
If this code works without rewriting:
e.Row.Attributes.Add("onclick", "location='CallCenter/BillDetails.aspx?billNo=" +
e.Row.Cells[0].Text + "'");
Then this should be not a problem with:
e.Row.Attributes.Add("onclick", "location='"location='orders/" +
e.Row.Cells[0].Text + "'");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.