Link to home
Start Free TrialLog in
Avatar of Billy Ma
Billy MaFlag for Hong Kong

asked on

C# ASP.NET loop and HTML

How can I get the data from the database and then I make my own HTML code
in C# ASP.NET?

Because one of my pages is really complicated.

you know, I wanna loop the data, (say company)
then in each company
i get all the process from the database according to the company selected,
then in each process,
i get the year rating, say 2008, 2009, 2010, 2011, 2012...

anyone can help me?
ASKER CERTIFIED SOLUTION
Avatar of sameer_goyal
sameer_goyal
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Billy Ma

ASKER

I am using Microsoft Visual Web Developer 2010 Express.

In my database, I have the following table
 User generated image
In my webpage, I have to show the company name, risk rating, scope of work, process risk rating and each year's selection. you know, those data are not stored in a single table. User is allowed to update the risk rating, process risk rating, and the year's selection. They update by just simple select the dropdown list.
 User generated image
Is it possible to do this in C# ASP.NET?
I hope you can help, sameer_goya!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
without dynamic HTML, I don't know how can I make the year column appear in each column, because my year was store in the table such as,
2010 H H
2011 H L
2012 L M
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i have written a very draft code to explain what I wanna do.
user can user drop down list to change the rating/selection
and then they click submit button at the bottom of the page,
then their changes will be made permanent in the database.

Is it hard to do so? Do you think write HTML code is ok?
Do you have other better way?

Could you please help do a sample of getting data and then present the data in the table?
and then the user can make changes.

Thank you!
variable_user_selected_year = 2010;

<TABLE>

SELECT COMPANY_ID, COMPANY_NAME, PROCESS_ID, PROCESS_NAME
FROM COMPANY C JOIN PROCESS P
WHERE C.COMPANY_ID = P.COMPANY_ID;

LOOP -- Company Loop

<TR>
   
   IF current_company <> last_company
       <TD> COMPANY_NAME </TD>

       SELECT ACTUAL_RATING
       FROM COMPANY_RATING
       WHERE COMPANY_ID = current_company_id_of_the_loop
       AND YEAR = currernt_year

      <TD>ACTUAL RATING</TD>
   else
       <TD> <TD>
   end if;

   <TD>PROCESS NAME</TD>

       SELECT ACTUAL_RATING
       FROM PROCESS_RATING
       WHERE PROCESS_ID = current_process_id_of_the_loop

   <TD>ACTUAL_RATING</TD>

       SELECT ACTUAL_SEL
       FROM PROCESS_SEL
       WHERE PROCESS_ID = current_process_id_of_the_loop
       AND YEAR = variable_user_selected_year - 2;


   <TD> 
        <select> 
             <option value = "" (if ACTUAL_SEL == "", selected)></option>
             <option value = "Y" (if ACTUAL_SEL == "Y", "selected)>Y</option>
             <option value = "*" (if ACTUAL_SEL == "*", "selected)>*</option>
             <option value = "^" (if ACTUAL_SEL == "^", "selected)>^</option>
             <option value = "#" (if ACTUAL_SEL == "#", "selected)>#</option>
             <option value = "##" (if ACTUAL_SEL == "##", "selected)>##</option>
             <option value = "@" (if ACTUAL_SEL == "@", "selected)>@</option>
        </select>
   </TD>

       SELECT ACTUAL_SEL
       FROM PROCESS_SEL
       WHERE PROCESS_ID = current_process_id_of_the_loop
       AND YEAR = variable_user_selected_year - 1;


   <TD> 
        <select> 
             <option value = "" (if ACTUAL_SEL == "", selected)></option>
             <option value = "Y" (if ACTUAL_SEL == "Y", "selected)>Y</option>
             <option value = "*" (if ACTUAL_SEL == "*", "selected)>*</option>
             <option value = "^" (if ACTUAL_SEL == "^", "selected)>^</option>
             <option value = "#" (if ACTUAL_SEL == "#", "selected)>#</option>
             <option value = "##" (if ACTUAL_SEL == "##", "selected)>##</option>
             <option value = "@" (if ACTUAL_SEL == "@", "selected)>@</option>
        </select>
   </TD>

       SELECT ACTUAL_SEL
       FROM PROCESS_SEL
       WHERE PROCESS_ID = current_process_id_of_the_loop
       AND YEAR = variable_user_selected_year;


   <TD> 
        <select> 
             <option value = "" (if ACTUAL_SEL == "", selected)></option>
             <option value = "Y" (if ACTUAL_SEL == "Y", "selected)>Y</option>
             <option value = "*" (if ACTUAL_SEL == "*", "selected)>*</option>
             <option value = "^" (if ACTUAL_SEL == "^", "selected)>^</option>
             <option value = "#" (if ACTUAL_SEL == "#", "selected)>#</option>
             <option value = "##" (if ACTUAL_SEL == "##", "selected)>##</option>
             <option value = "@" (if ACTUAL_SEL == "@", "selected)>@</option>
        </select>
   </TD>


       SELECT ACTUAL_SEL
       FROM PROCESS_SEL
       WHERE PROCESS_ID = current_process_id_of_the_loop
       AND YEAR = variable_user_selected_year + 1;


   <TD> 
        <select> 
             <option value = "" (if ACTUAL_SEL == "", selected)></option>
             <option value = "Y" (if ACTUAL_SEL == "Y", "selected)>Y</option>
             <option value = "*" (if ACTUAL_SEL == "*", "selected)>*</option>
             <option value = "^" (if ACTUAL_SEL == "^", "selected)>^</option>
             <option value = "#" (if ACTUAL_SEL == "#", "selected)>#</option>
             <option value = "##" (if ACTUAL_SEL == "##", "selected)>##</option>
             <option value = "@" (if ACTUAL_SEL == "@", "selected)>@</option>
        </select>
   </TD>

       SELECT ACTUAL_SEL
       FROM PROCESS_SEL
       WHERE PROCESS_ID = current_process_id_of_the_loop
       AND YEAR = variable_user_selected_year + 2;


   <TD> 
        <select> 
             <option value = "" (if ACTUAL_SEL == "", selected)></option>
             <option value = "Y" (if ACTUAL_SEL == "Y", "selected)>Y</option>
             <option value = "*" (if ACTUAL_SEL == "*", "selected)>*</option>
             <option value = "^" (if ACTUAL_SEL == "^", "selected)>^</option>
             <option value = "#" (if ACTUAL_SEL == "#", "selected)>#</option>
             <option value = "##" (if ACTUAL_SEL == "##", "selected)>##</option>
             <option value = "@" (if ACTUAL_SEL == "@", "selected)>@</option>
        </select>
   </TD>

</TR>

END LOOP -- END COMPANY LOOP

</table>

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi satishratnaparkhi:, i afraid the link you gave me was already have the html code, however, what I need is dynamically generate HTML code.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok, i see, thank you!
but how can I display that dynamiclly generated code on my page?
just create a label and the whole html code to that label?

How can know which value does the user changed and then I can make update.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
but I am using the template which contains a site.master
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How can I create an action, whenever a user change the box, I want some action and do some update, how can I do that?

I have attached my code.
If user change any value in any dropdown list, I have to call a function.

how to do that?
Test.aspx
Test.aspx.cs
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i think you guys are right, I should use GridView.

Because I cannot get the dropdown list....

Ok, I use GridView if everyone think it is good.

But how can I do that in database? Oracle Stored Procedure seems won't work, because I cannot just write a SELECT statement in store proc and get the result.

Should I make 2 connection? first execte the stored proc and then do all the data processing and input those data into a temp table
and then get the result from the temp table?

Or should I create a ASP.NET table control and then dynamically create columns and rows?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Anyone can let me know how to install the Oracle Data Access Components?
Can you also let me know what should I add in my code?
you know I have lots of "USING ....." on the top of my page.
should I add using data.ODAC? something like that?

What is the connection string format?

I have create a procedure already, can you use my example to get the data from it?

as long as I know how to get the data from the procedure, then I can do some complex things.

Hope any of you can help me.
CREATE OR REPLACE PROCEDURE "RISK_MGR"."GET_CURSOR"(P_RC1 OUT SYS_REFCURSOR) IS
BEGIN

   OPEN P_RC1 FOR
   SELECT COMPANY_ID, COMPANY_NAME
   FROM COMPANY;

END;

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In fact, what is your database? Are you using Oracle or Sql Server?
Thank you so much!
The ODACs are placed here:

http://www.oracle.com/technetwork/database/windows/downloads/index-101290.html

You really should consider using oledb instead of odbc due to performance reasons.
Add a reference to System.Data.OracleClient. Same is the namespace. I remember I had some errors with Microsoft's oracle odbc regarding blob and clob fields, so this might not be first choice.