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

I have a completed asp.net 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.

-Scott
heyday2004Asked:
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.
0
 
AerosSagaCommented:
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

Aeros
0
 
AerosSagaCommented:
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

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

0
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:
LabelTest1.Text=Value1;...

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

Thanks,
Scott
0
 
AerosSagaCommented:
Me.LabelTest1.Text = "returned value"

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

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

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
 
<html>
   <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);
 
            dt.Rows.Add(dr);
         }
 
         DataView dv = new DataView(dt);
         return dv;
      }
 
      void Page_Load(Object sender, EventArgs e)
      {
 
         if (!IsPostBack)
         {
            // Load this data only once.
            ItemsGrid.DataSource= CreateDataSource();
            ItemsGrid.DataBind();
         }
      }
 
   </script>
 
<body>
 
   <form runat=server>
 
      <h3>DataGrid Example</h3>
 
      <b>Product List</b>
 
      <asp:DataGrid id="ItemsGrid"
           BorderColor="black"
           BorderWidth="1"
           CellPadding="3"
           AutoGenerateColumns="true"
           runat="server">

         <HeaderStyle BackColor="#00aaaa">
         </HeaderStyle>
 
      </asp:DataGrid>
 
   </form>
 
</body>
</html>

Here is the description for using ExecuteNonQuery and ExecuteReader:

URL: http://www.aspnet101.com/aspnet101/tutorials.aspx?id=18

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 http://aspnet101.com/aspnet101/aspnetcode.aspx 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.
0
 
heyday2004Author Commented:
Thanks, all!
0
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.