1

I have a GirdView populated with text from code behind, I want to have a row contains a text and another row contains a 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 GridView row :

2
  • "another row" or "another column" to contain hyperlink? Couldn't you do it in the markup? Commented Dec 9, 2012 at 7:50
  • could you be a little more elaborate? Commented Dec 10, 2012 at 12:46

2 Answers 2

2

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!

Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.