[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2004-10-27
10
Medium Priority
?
455 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
Comment
Question by:heyday2004
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12428223
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
ID: 12428233
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

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

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:heyday2004
ID: 12428507
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:
AerosSaga earned 900 total points
ID: 12428516
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
ID: 12428521
Me.LabelTest1.Text = "returned value"

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

Expert Comment

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

Assisted Solution

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

Assisted Solution

by:nauman_ahmed
nauman_ahmed earned 900 total points
ID: 12429859
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
ID: 12440775
Thanks, all!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

649 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