首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >设置动态asp:HyperLinkField

设置动态asp:HyperLinkField
EN

Stack Overflow用户
提问于 2019-02-21 17:55:49
回答 1查看 75关注 0票数 0

我有一个网格视图,它在页面加载dataReader时被填充。

我可以添加一个带有超链接的列,但我需要url包含动态添加到gridView的GenCod,以便每个链接发送到其详细信息页面。

URL示例:http://localhost:50228/misesenventedetail.aspx?GenCod=9788416657544

如何使用列的索引或名称来获取GenCod?

代码语言:javascript
复制
<asp:GridView ID="aParaitre_GridView" runat="server" OnRowCommand="RowCommand" >
   <Columns>
     <asp:ButtonField buttontype="Image" CommandName="AjouterAuPanier" ImageUrl="~/Images/buy_this_logo.png" />
     <asp:HyperLinkField NavigateUrl="url+Parameter+GENCOD" Text="VoirDetail" />
   </Columns>
</asp:GridView>

此GridView包含更多列。

获取错误: System.Web.UI.WebControls.HyperLinkField没有DataBinding。

使用以下代码:

代码语言:javascript
复制
<asp:HyperLinkField               
     NavigateUrl='<%# String.Format("~/misesenventedetail.aspx?GenCod={0}", Eval("GenCod"))%>'
     Text="Detail" 
     runat="server"
     />

我希望像这样的东西能行得通

代码语言:javascript
复制
 <asp:HyperLinkField
     id="MyLink"
     NavigateUrl="~/misesenventedetail.aspx?GenCod<%= gencod %>"
     runat="server" />


  protected void RowCommand(object sender, GridViewCommandEventArgs e)
  {
     // Gets the index of the line (row) where we click
     int index = Convert.ToInt32(e.CommandArgument);

     GridViewRow ligneClick = aParaitre_GridView.Rows[index];

     // Gets GenCod from column 1
     var GenCod = ligneClick.Cells[1].Text;

     MyLink.NavigateUrl = string.Format("../mypage.aspx?id={0}", GenCod );

  }
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54804152

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档