Solved

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

Posted on 2004-10-27
450 Views
Last Modified: 2011-09-20
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
0
Question by:heyday2004
    10 Comments
     
    LVL 17

    Expert Comment

    by:AerosSaga
    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
     
    LVL 17

    Expert Comment

    by:AerosSaga
    http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

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

    0
     
    LVL 17

    Expert Comment

    by:AerosSaga
    0
     

    Author Comment

    by:heyday2004
    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
     
    LVL 17

    Accepted Solution

    by:
    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
     
    LVL 17

    Expert Comment

    by:AerosSaga
    Me.LabelTest1.Text = "returned value"

    that will work if its a server control text box
    0
     
    LVL 3

    Expert Comment

    by:nitrogenx
    Page.FindControl("LabelTest1").Text
    0
     
    LVL 3

    Assisted Solution

    by:nitrogenx
    or even Table1.FindControl("LabelTest1") depending on how well you know where it is
    0
     
    LVL 25

    Assisted Solution

    by:nauman_ahmed
    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
     

    Author Comment

    by:heyday2004
    Thanks, all!
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    Ajax and MVC 2 36
    HTML control 6 30
    Passing data from controller to view 6 28
    Server 2012 R2:  .NET framework does not work 4 31
    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now