回发后保留 Gridview 超链接列

Retaining Gridview hyperlink column after postback

我有一个在代码隐藏 (gridView_RowDataBound) 中创建的超链接 Gridview 列,它在 postabk 上变成纯文本。超链接的text和NavigateUrl是动态生成的gridview的cell[0]的值

` protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HyperLink link = new HyperLink();
                link.Target = "blank";
                link.Text = e.Row.Cells[0].Text;
                link.NavigateUrl = e.Row.Cells[0].Text;
                e.Row.Cells[0].Controls.Add(link);

            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }`

我正在尝试对 RowCreated 事件做同样的事情,以确保在回发时保留超链接。但是Gridview中的数据丢失了,所以我无法以同样的方式访问它。

对于遇到相同问题的任何人,这是我在每次加载页面时所做的(回发)

protected void GridViewDisplayDocument_RowCreated()
{
   var rowCount = GridViewDisplayDocument.Rows.Count;
   for (int i = 0; i < rowCount; i++)
   {
      var url = GridViewDisplayDocument.Rows[i].Cells[0].Text;
      if (url != string.Empty)
      {
         HyperLink link = new HyperLink();
         link.Target = "blank";
         link.Text = url;
         link.NavigateUrl =  url;

         GridViewDisplayDocument.Rows[i].Cells[0].Controls.Add(link);
       }
    } 
}