views:

170

answers:

1

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_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. 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

+3  A: 

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";
  }
}
Muhammad Akhtar
You need to create a TemplateColumn for that solution
citronas
I tried this, but the Hyperlinkfield does not have an ID property so I cant "find" it with a call to FindControl.
JohnG