c#
  • asp.net
  • gridview
  • url-rewriting
  • 2012-11-08 35 views 0 likes 
    0

    我在我的網站中使用Url重寫。從ASP.NET 4.0 GridView中的URL重寫

    我能夠重寫使用

    Response.RedirectToRoute("bills-show"); 
    
    從我的GridView

    但我怎麼能重定向到另一頁面的URL? 當前我在我的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 }); 
    } 
    

    ,但是這是不工作!

    你能幫我嗎?

    +0

    你的新網址看起來像? – Uriil

    +0

    'website.com/orders/127'這裏'127'是'billNo' –

    回答

    0

    使用HyperLinkField在GridView的列列表:

    <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 + "'"); 
    
    +0

    目前在我的gridview中,當我點擊gridview行的任何地方時,頁面將被重定向。我想保留相同的過程並應用URL重寫.. –

    相關問題