0

I need your help on this. In my copde I am using data table ... manually creating rows/columns in DT and populating them and lastly binding it to GridView.

I want to add a cell to each datarow in data table and the cell in turn will hold a HTML Control (HTML Anchor Tag).

Say, my current DT has 2rows and 3 cols as below

server blah blah abc xyz 123 def vbh 345 

Now, I want to do further processing on servername (on col1) and add a extra col to DT which will hold HTML Anchor Tag. the details can be seen clicking on the HTML Anchor tag. So, ultimately the DT should look like below:

server blah blah abc xyz 123 HTML LINK def vbh 345 HTML LINK 

Please tell how can I do this? i.e, add a separate cell to DT and add the HTML control to that bewly added cell.

Thanks. Rahul

1
  • Would you mind marking some of your questions as answered? Commented Feb 3, 2011 at 12:56

2 Answers 2

1

One way to do it would be to create a model class that you can bind to that wraps each data row:

public class FooView { public FooView(Row row) { this.Row = row; } private Row Row { get; set; } public string Server { get { (string)return this.Row["Server"]; } } public string Blah{ get { (string)return this.Row["blah"]; } } public string Link1{ get { string.Format("http://foo.bar/id={0}", this.Server); } } } 

Create a list of these and bind directly to this collection (using the Link1 property to get the href for the link).

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

Comments

0

While I agree with RQDQ, here is an alternative method:

Dim newColumn As New Data.DataColumn("HyperlinkColumn") dt.Columns.Add(newColumn) For Each r As Data.DataRow In dt.Rows r("HyperlinkColumn") = "http://www.whatevervalue.com" Next 

Where dt is the Datatable you are using.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.