1

GirdView从后面的代码中填充了一个文本,我想让一行包含一个文本,另一行包含一个HyperLink.

我使用以下代码:

  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()

如何将超链接添加到GridView行:

4

2 回答 2

2

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

于 2012-12-10T05:53:38.530 回答
1

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

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);
于 2012-12-10T09:43:56.170 回答