how to return and display results in an ASP.NET table?

I have a completed table, what I intend to do is after calling a stored procedure in SQL Server, I need to return and display the several columns of one record to the table (by replacing the labels of each cell with new data from the database). The table format is like:
<asp:table id="Table1" ...
  <asp:TableCell ...
    <asp:Label ID="LabelTest1", Text="..."...

What i want to do is like this: Table1.LabelTest1.Text = "returned value";
Of course, it's not allowed in ASP.NET.

In my design, the return values are five output parameters from a stored procedure. So basically, just one input parameter (user ID) and returned related information of that user(five output parameters of the stored procedure). Also, i need to insert related data to another table in the stored procedure.
My question is: Is there a better ASP.NET database scenario for this? How to display returned results in an existing table? Is it good to use five output parameters of the stored procedure? Is there any other better designs? Also, since the stored procedure i wrote involves two actions:
1. validation the user ID and retrieving the user information by using output parameters;
2.  inserting the time, and other activity information to a new table.
Shall I use ExecuteNonQuery or ExecuteReader? Thanks a lot for any suggestion.

Who is Participating?
AerosSagaConnect With a Mentor Commented:
if you don't want to use a datarid just use a standard html table with server control textboxes.  The asp:table does not work very well trust me.  If they are server controls they weill need a unique ID this is required.
1) just use a range validator for 1-100000000000 or whatever to ensure its a number
2) use a datagrd thats what this was built for I'll post some helpful links in a sec


also the asp:table is kinda buggy, so be forwarned.

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

heyday2004Author Commented:
Thanks. Actually, i just need to return maybe four variables to the frontend tables, assume the table is like this:
<asp:table id="Table1" ...
  <asp:TableCell ...
    <asp:Label ID="LabelTest1", Text="..."...

 I can assign the four values to the table one by one using Label ID like this:

What's wrong with this? Seems this is simpler because there are just four values to return, to display? Do I still need to use DataGrid? BTW, how to use the designed table which was already there (just need to update some data) using DataGrid? Doesn't DataGrid build a new table?

One more small question: is it required in ASP.NET that the ID "LabelTest1" in above table should be unique among multiple tables? What if there are many tables and there is naming collision?

I need to study more on DataGrid, i think...

Me.LabelTest1.Text = "returned value"

that will work if its a server control text box
nitrogenxConnect With a Mentor Commented:
or even Table1.FindControl("LabelTest1") depending on how well you know where it is
nauman_ahmedConnect With a Mentor Commented:

Why dont you use the DataGrid to populate your control? Here is an example:

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
   <script language="C#" runat="server">
      ICollection CreateDataSource()
         DataTable dt = new DataTable();
         DataRow dr;
         dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
         dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
         dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));
         for (int i = 0; i < 9; i++)
            dr = dt.NewRow();
            dr[0] = i;
            dr[1] = "Item " + i.ToString();
            dr[2] = 1.23 * (i + 1);
         DataView dv = new DataView(dt);
         return dv;
      void Page_Load(Object sender, EventArgs e)
         if (!IsPostBack)
            // Load this data only once.
            ItemsGrid.DataSource= CreateDataSource();
   <form runat=server>
      <h3>DataGrid Example</h3>
      <b>Product List</b>
      <asp:DataGrid id="ItemsGrid"

         <HeaderStyle BackColor="#00aaaa">

Here is the description for using ExecuteNonQuery and ExecuteReader:


ExecuteReader - basically, this method returns a DataReader which is filled with the data that is retrieved using the command. This is known as a forward-only retrieval of records - it uses your sql statement to read through the table from the first to the last.
There are many DataReader examples on this site. Just go to and choose DataReader from the DropDownList

Useage: cmd.ExecuteReader
ExecuteNonQuery - this method returns no data at all. It is used mainly with Inserts and Updates of tables.
Here, also, we have many code samples using ExecuteNonQuery.

Best, Nauman.
heyday2004Author Commented:
Thanks, all!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.