如何将gridview中的列设置为自动生成的超链接

tin*_*inu 3 .net c# asp.net gridview

我想制作gridview.columns[0]as超链接.我在不同的网站上尝试了很多工作.我绑定list<>到网格.我需要将第一列作为超链接,点击该链接后,应将其重定向到包含相应项目的页面.我需要使用哪个事件以及如何从列表中传递该值?

Yur*_*kiy 8

void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        var firstCell = e.Row.Cells[0];
        firstCell.Controls.Clear();
        firstCell.Controls.Add(new HyperLink { NavigateUrl = firstCell.Text, Text = firstCell.Text });
    }
}
Run Code Online (Sandbox Code Playgroud)

请注意,如果仅在第一次加载页面时将数据绑定到网格,则更改将消失.