GridView HyperLink field in C#

后端 未结 5 586
梦如初夏
梦如初夏 2020-12-17 16:43

Take a look at the following code:



        
5条回答
  •  有刺的猬
    2020-12-17 17:35

    Use the DataNavigateUrlFields property, comma-delimited value with the fields for parameters in "KeywordSrchSumDtl.aspx?Keyword={0}&State={1}&City={2}"

    
    

    A couple of examples:

    Passing two arguments in DataNavigateUrlFormatString in hyperlink field of .NET 2.0 Grid-View

    Pass Multiple Values from a GridView to Another Page using ASP.NET

    EDIT:

    Set NavigateUrl of HyperLink in RowDataBound event of GridView

    
       
          
              
          
        
        .......
    
    

    Code behind:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
        HyperLink hl = (HyperLink)e.Row.FindControl("link"); 
        if (hl != null) 
        { 
            DataRowView drv = (DataRowView)e.Row.DataItem; 
            string keyword = drv["Keyword"].ToString(); 
            string state = Request.QueryString["State"]; 
            string city = Request.QueryString["City"]; 
            hl.NavigateUrl = "~/KeywordSrchSumDtl.aspx?Keyword=" + keyword + "&State=" + Server.UrlEncode(state) + "&City=" + Server.UrlEncode(city); 
        } 
     } 
    }
    

提交回复
热议问题