2012-04-12 74 views
1

I want a text in my datatable to have a link to a another page. And I do this by the means of the business layer.如何使文本有一個<a ref> tag in business layer in ASP

here is my code:

DataTable reportTable = new DataTable();

 DataColumn colLeaveType = new DataColumn("leaveType", typeof(System.String)); 
     DataColumn colNoDays = new DataColumn("No. of Days", typeof(System.Int32)); 
     DataColumn colStartDate = new DataColumn("Start Date", typeof(System.String)); 
     DataColumn colEndDate = new DataColumn("End Date", typeof(System.String)); 
     DataColumn colConvert = new DataColumn("Convert To Leave", typeof(System.String)); 


     reportTable.Columns.Add(colLeaveType); 
     reportTable.Columns.Add(colNoDays); 
     reportTable.Columns.Add(colStartDate); 
     reportTable.Columns.Add(colEndDate); 
     reportTable.Columns.Add(colConvert); 

     reportTable.AcceptChanges(); 

     foreach (DataRow row in tempTable.Rows) { 
      DataRow newRow = reportTable.NewRow(); 
      reportTable.Rows.Add(newRow); 

      newRow[colLeaveType] = row["LeaveType"].ToString(); 
      newRow[colNoDays] = row["DaysCredit"].ToString(); 
      newRow[colStartDate] = row["StartDate"].ToString(); 
      newRow[colEndDate] = row["EndDate"].ToString(); 
      newRow[colConvert] = "Convert"; // this is something like this <a href="newPage"> Convert </a> 

      reportTable.AcceptChanges(); 
     } 

How to do this? Is this possible?

Thanks

RJUY

回答

0
newRow[colConvert] = "<a href='newPage'>" + row["Convert"].ToString() + "<a/>"; 

Of course you really need to test the values from your database for null before you cast them. And using a StringBuilder to generate the link would also be best.

+0

It didn't work. I shows the text literally "Convert「..爲什麼會這樣這裏是代碼NEWROW [colConvert] =?」 Convert「; – user1306165 2012-04-12 03:38:19