我有一个网格视图,它在页面加载dataReader时被填充。
我可以添加一个带有超链接的列,但我需要url包含动态添加到gridView的GenCod,以便每个链接发送到其详细信息页面。
URL示例:http://localhost:50228/misesenventedetail.aspx?GenCod=9788416657544
如何使用列的索引或名称来获取GenCod?
<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。
使用以下代码:
<asp:HyperLinkField
NavigateUrl='<%# String.Format("~/misesenventedetail.aspx?GenCod={0}", Eval("GenCod"))%>'
Text="Detail"
runat="server"
/>
我希望像这样的东西能行得通
<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 );
}
发布于 2019-02-21 19:32:49
已解决
我能够用这个解决我的问题:
<asp:HyperLinkField
DataNavigateUrlFields="GenCod" DataNavigateUrlFormatString="~/misesenventedetail.aspx?GenCod={0}" Text="Voir Details"
runat="server" />
StackOverflow太棒了。
https://stackoverflow.com/questions/54804152
复制相似问题