vb.net 如何在asp.net中向GridView Row动态添加超链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13785523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:30:22  来源:igfitidea点击:

How to add Hyperlink dynamically to GridView Row in asp.net

asp.netvb.netgridviewhyperlink

提问by Adham

I have a GirdViewpopulated with text from code behind, I want to have a row contains a text and another row contains a HyperLink.

我有一个GirdView来自代码后面的文本填充,我想让一行包含一个文本,另一行包含一个HyperLink.

I use the following code :

我使用以下代码:

  Dim dtFull As New DataTable()
            ' Create four typed columns in the DataTable.
        dtFull.Columns.Add("Self Assessment", GetType(Object))
        dtFull.Columns.Add("Staff Development", GetType(Object))
        dtFull.Columns.Add("Mid Meeting", GetType(Object))
        dtFull.Columns.Add("Objectives Rating", GetType(Object))
        dtFull.Columns.Add("Overall Rating", GetType(Object))
        dtFull.Columns.Add("Second Supervisor Approval", GetType(Object))
        dtFull.Columns.Add("Staff Sign Off", GetType(Object))
        dtFull.Columns.Add("Total", GetType(Object))

        dtFull.Rows.Add("", "", "", "", "", "", "", "")
        gvGeneralStatistics.DataSource = dtFull
        gvGeneralStatistics.DataBind()

How to add HyperLink to the GridViewrow :

如何向GridView行添加超链接:

回答by Ammar Hamidou

try to have a TemplateField in your GridView. and add the hyperlink inside the template field. you set the hyperlinks values manually from the GridView Columns, or from the code behind in even Row Data Bound!

尝试在您的 GridView 中有一个 TemplateField。并在模板字段中添加超链接。您可以从 GridView 列手动设置超链接值,或者从甚至行数据绑定中的代码后面!

回答by Satinder singh

I prefer to use TemplateField coz of its simplicity. But if you want to add dynamically you can do it like

我更喜欢使用 TemplateField,因为它很简单。但是如果你想动态添加你可以这样做

C#:

C#:

HyperLinkField hplnk = new HyperLinkField();
hplnk.DataTextField = "YourValue";
hplnk.HeaderText = "yourHeaderTextValue";
gvGeneralStatistics.Columns.Add(hplnk);

Vb.net:

网络:

Dim hplnk As New HyperLinkField()
hplnk.DataTextField = "YourValue"
hplnk.HeaderText = "yourHeaderTextValue"
gvGeneralStatistics.Columns.Add(hplnk);