gpt4 book ai didi

C# 添加 HyperLinkColumn 到 GridView

转载 作者:太空宇宙 更新时间:2023-11-03 20:47:14 25 4
gpt4 key购买 nike

我正在尝试将 HyperLinkColumns 动态添加到我的 GridView。我有以下代码:

HyperLinkColumn objHC = new HyperLinkColumn();
objHC.DataNavigateUrlField = "title";
objHC.DataTextField = "Link text";
objHC.DataNavigateUrlFormatString = "id, title";
objHC.DataTextFormatString = "{2}";

GridView1.Columns.Add(objHC);

这不起作用,所以..我怎样才能将 HyperLinkColumn 添加到我的 GridView?

最佳答案

您可能希望在绑定(bind)行时添加它:

protected void yourGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
HyperLink hlControl = new HyperLink();
hlControl.Text = e.Row.Cells[2].Text; //Take back the text (let say you want it in cell of index 2)
hlControl.NavigateUrl = "http://www.stackoverflow.com";
e.Row.Cells[2].Controls.Add(hlControl);//index 2 for the example
}

关于C# 添加 HyperLinkColumn 到 GridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/324682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com