如何在c#代码后面的gridview中将值绑定到超链接 [英] how to bind value to hyperlink in gridview in c# code behind
本文介绍了如何在c#代码后面的gridview中将值绑定到超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个自定义网格,我在我的c#代码后面绑定了数据。我给我的一个专栏提供了一个超链接字段。如果我单击超链接值,它应该导航到该超链接值的详细信息页面。代码如下:
protected void grd_RowDataBound( object sender,GridViewRowEventArgs e)
{
if (e .Row.RowType == DataControlRowType.DataRow)
{
HyperLink myLink = new HyperLink();
myLink.Text = e.Row.Cells [ 2 ]。文字;
e.Row.Cells [ 2 ]。Controls.Add(myLink);
myLink.NavigateUrl = Estimation.aspx?EstimateID = + EstimateID + & VersionNo = + VersionNo;
}
}
如果我点击链接,页面会被导航,但我没有得到已在页面中预先加载的详细信息。请给我关于如何纳入这个的建议。谢谢
解决方案
在aspx页面中这样使用
< asp:linkbutton id = lnkid text = <%#Eval( text )%> runat = server postbackurl = <%#Eval( EstimateID ,〜/ Estimation.aspx?EstimateID = { 0 }& VersionNo = { 0 } )%>'>< / asp:linkbutton>
如果问题解决,则将其标记为接受colution
http://csharpdotnetfreak.blogspot.com/2011/09/querystring-in-aspnet.html [ ^ ]
http://msdn.microsoft.com/en-us/library/6c3yckfw(v=vs.100)。 aspx [ ^ ]
Hi guys,
I have a custom grid on which i have binded data in my c# code behind. I have given a hyperlink field to one of my column. If i click the hyperlink value, it should navigate to the details page of that hyperlink value. The code is given below,
protected void grd_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink myLink = new HyperLink();
myLink.Text = e.Row.Cells[2].Text;
e.Row.Cells[2].Controls.Add(myLink);
myLink.NavigateUrl = "Estimation.aspx?EstimateID=" + EstimateID + "&VersionNo=" + VersionNo;
}
}
If i click the link, the page is getting navigated, but i am not getting the details which are already pre-loaded in that page. Please give me suggestions on how to incorporate this. Thanks
解决方案
use like this in aspx page
<asp:linkbutton id="lnkid" text="<%# Eval("text") %>" runat="server" postbackurl="<%# Eval("EstimateID","~/Estimation.aspx?EstimateID={0}& VersionNo={0}") %>'></asp:linkbutton>
if problem solved then mark it as accept colution
http://csharpdotnetfreak.blogspot.com/2011/09/querystring-in-aspnet.html[^]
http://msdn.microsoft.com/en-us/library/6c3yckfw(v=vs.100).aspx[^]
这篇关于如何在c#代码后面的gridview中将值绑定到超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文