2012-04-12 12 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

関連する問題