Rahul
Rahul

Reputation: 77866

need clarification on Datatable

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

Upvotes: 0

Views: 133

Answers (2)

Rajeev Nair
Rajeev Nair

Reputation: 759

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.

Upvotes: 0

RQDQ
RQDQ

Reputation: 15569

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

Upvotes: 1

Related Questions