简体   繁体   中英

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

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";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM