Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi expert,

In asp.net application,


In .aspx design view i have add one table control <asp:Table runat="server" ID="resultTable" Width="511px">

now i have to show results from .aspx.cs file which contain database results

Like this,

C#
int totalRec = dataresult().Rows.Count;
  int index;

   for (index = 0; index < totalRec ; index++)
    {


Response.write("table tag> ,table row>"+
C#
string   a=dataresult().Rows[0][2].ToString();
               if( dataresult().Rows[0][3]!="N/A" ){
                 a=a +"," + dataresult().Rows[0][3].ToString();
                                                    }

+" /td /tr /table");
}


How i can show above result it in resultTable control


Or Suggest me any other control from which i have easily generate table tag from code behind page for dynamic result.

Thanks in advance.
Posted
Updated 15-Sep-11 0:42am
v4

Use Literal. This is something like this

you dont need to use Table control. Just build the string with table tag and assign it to the Literal control.

C#
<asp:literal id="Literal1" runat="server">


And from server side assign the string to its text property like

Literal1.Text=your string;
 
Share this answer
 
v2
Comments
udusat13 15-Sep-11 7:04am    
Thanks For reply
me

I am trying now
Md. Rashim Uddin 15-Sep-11 7:41am    
Okay and if it solves your problem mark it as answer
you can do:
C#
foreach (DataRow row in dataresult().Rows)
{
    TableRow tRow = new TableRow();
    foreach (var item in row.ItemArray)
    {
        TableCell cell = new TableCell();
        cell.Text = item.ToString();
        t.Row.Cells.Add(cell);
     }
    resultTable.Rows.Add(tRow);
}


if you need specific items form row.ItemArray, specify these in stead of iteration over all the values in the DataRow object
 
Share this answer
 
v2
Comments
udusat13 15-Sep-11 7:03am    
Thanks....
i got idea.
Solution 1 is fine to show your result, thanks

Another way you can show your result by using GridView which will generate html table and not necessary much coding in code behind. If you need the code for showing data in GridView, please reply me I&#39;ll post that. Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900