[英]Modify Hyperlinkfield text in Gridview
I am stumped on this one. 我为此感到困惑。 I want to modify the text in a Hyperlinkfield of Gridview after the data is bound to it.
我想在数据绑定到Gridview的Hyperlinkfield中修改文本。 I found similar code to this on msdn and I can't get it to work.
我在msdn上发现了与此类似的代码,但无法正常工作。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[2].Text = e.Row.Cells[2].Text + "random text";
}
I also tried similar code in the Page_PreRender event with no luck. 我也没有在Page_PreRender事件中尝试过类似的代码。 I have also tried calling DataBind() before this one line of code with no help.
我也曾尝试在这一行代码之前没有帮助地调用DataBind()。 I always just get "random text" in the cell without the data from the DB.
我总是只在单元格中获得“随机文本”,而没有来自DB的数据。 Thanks
谢谢
I think you should try like... 我想你应该尝试...
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink hyp = (HyperLink)e.Row.Findcontrol("YourHyperlinkID");
hyp.Text = "Your New Text";
}
}
I found your question while trying to figure this out myself (based-on a similar answer ). 我试图自己弄清楚 (基于类似答案 )时发现了您的问题。 I see this question was from a while ago, but I wanted to answer it in case someone else found it looking for answers.
我看到这个问题是前一段时间的,但是我想回答这个问题,以防其他人发现它在寻找答案。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[2].Controls[0].Text = e.Row.Cells[2].Controls[0].Text + "random text";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.