【问题标题】:URL Rewriting from GridView in ASP.NET 4.0在 ASP.NET 4.0 中从 GridView 重写 URL
【发布时间】:2012-11-08 06:47:13
【问题描述】:

我正在我的网站中使用 URL 重写。

我可以使用

重写网址
Response.RedirectToRoute("bills-show");

但是如何从我的 GridView 重定向到另一个页面? 目前我在GridViewRowDataBound 中使用以下代码。

e.Row.Attributes.Add("onclick", "location='CallCenter/BillDetails.aspx?billNo=" + e.Row.Cells[0].Text + "'");

但我需要的是使用 URL 重写。

我尝试过使用

e.Row.Attributes.Add("onclick", "WriteUrl(" + e.Row.Cells[0].Text + ")"); // in GridViewRowDataBound.

protected string WriteUrl(string billNo)
{
    return pg.GetRouteUrl("bill-details", new { billno = billNo });
}

但这不起作用!!!

你能帮帮我吗???

【问题讨论】:

  • 你的新网址会是什么样子?
  • website.com/orders/127 这里127billNo

标签: c# asp.net gridview url-rewriting


【解决方案1】:

在 GridView 列列表中使用HyperLinkField

    <asp:HyperLinkField HeaderText="Account" DataTextField="Account" 
    DataNavigateUrlFields="Account" Target="_blank" 
    DataNavigateUrlFormatString="CallCenter/BillDetails.aspx?billNo=n={0}"
    SortExpression="Account" HeaderStyle-Width="61" />

如果此代码无需重写即可工作:

    e.Row.Attributes.Add("onclick", "location='CallCenter/BillDetails.aspx?billNo=" +
                              e.Row.Cells[0].Text + "'");

那么这应该不是问题:

    e.Row.Attributes.Add("onclick", "location='"location='orders/" +
                              e.Row.Cells[0].Text + "'");

【讨论】:

  • 当前在我的 gridview 中,当我单击 gridview 行上的任意位置时,页面将被重定向。我想保留相同的过程并应用 URL 重写..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-02
相关资源
最近更新 更多