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. I found similar code to this on msdn and I can't get it to work.
protected void GridView1_Row开发者_StackOverflowDataBound(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. I have also tried calling DataBind() before this one line of code with no help. I always just get "random text" in the cell without the data from the 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";
}
精彩评论