PDA

View Full Version : asp.net presentation of data


darktown
10-12-2004, 09:51 AM
Hi,

the main idea : select information from a table and show it.

I have done an include of top.aspx
top.aspx is a file where my top banner & left menu are put in.


<HTML>
<HEAD>
<title>top</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<LINK href="Styles.css" type="text/css" rel="stylesheet">
<script type="text/javascript" language="JavaScript">

</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<table width="90%" height ="100%" cellspacing="0" cellpadding="0" align="center">
<tr width="100%" align ="center">
<!-- Show hostname & other options -->
<td class="small" align="left">&nbsp;</td>
<td class="small">Your Machinename : <% response.write(session("Hostname"))%>|&nbsp;|Succesfully Logged in as :<% response.write(session("Username"))%></td>
<td class="small" align="right"><% response.write(session("IP")) %></td>
</tr> <!-- End first row -->
<tr>
<td width="120" align="left" valign ="top"><!-- Left Menu Here -->
<br/>
<!-- Information:-->
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td height="26" class="itemHeader">Information</td>
</tr>
<tr>
<td width="120" class="menu"><a href='information.aspx?topic=profile'>&nbsp; ×My
Profile</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='information.aspx?topic=member'>&nbsp; ×MemberList</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='information.aspx?topic=staff'>&nbsp; ×Staff</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='information.aspx?topic=recruitment'>&nbsp;
×Recruitment</a></td>
</tr>
</table>
<br/>
<!-- General:-->
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td height="26" class="itemHeader">General</td>
</tr>
<tr>
<td width="120" class="menu"><a href='general.aspx?topic=history'>&nbsp; ×History</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='general.aspx?topic=links'>&nbsp; ×Links</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='general.aspx?topic=linkus'>&nbsp; ×Link Us?</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='general.aspx?topic=contact'>&nbsp; ×Contact</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='general.aspx?topic=forum'>&nbsp; ×Forum</a></td>
</tr>
</table>
<br/>
<!-- Media:-->
<table border="1" cellpadding="0" cellspacing="0">

</table>
<br/>
</td> <!-- End Left Menu: -->
<td valign="top"> <!-- Main Start Here: -->



afterwards in my vb code i do a select of my data and i want it to appear in my body of the page. but everytime my data appears above my <html> tag.


query = "select * from tbluserinformation order by Username"

If connOK = True Then
scmd.CommandText = query
scmd.Connection = myConnection
sdr = scmd.ExecuteReader()
Response.Write("<table width='100%'>")
While sdr.Read


bday = Split(sdr.GetString(6), "-")
birthday = bday(2) & "-" & bday(1) & "-" & bday(0)

Response.Write("<tr><td>'" & sdr.GetString(1) & "'</td></tr>")
Response.Write("<tr><td>'" & sdr.GetString(2) & "'</td></tr>")
Response.Write("<tr><td>'" & sdr.GetString(3) & "'</td></tr>")
Response.Write("<tr><td>'" & sdr.GetString(4) & "'</td></tr>")
Response.Write("<tr><td>'" & sdr.GetString(5) & "'</td></tr>")
Response.Write("<tr><td>'" & sdr.GetString(7) & "'</td></tr>")
Response.Write("<tr><td>'" & sdr.GetString(8) & "'</td></tr>")
Response.Write("<tr><td>'" & sdr.GetString(9) & "'</td></tr>")
Response.Write("<tr><td>'" & sdr.GetString(10) & "'</td></tr>")
Response.Write("<tr><td>'" & birthday & "'</td></tr>")

End While
Response.Write("</table>")
sdr.Close()
End If


My Question : how to make my data appear in the body of the page instead of totally on top?

I also include a bottum.aspx (i close my tables correctly and so..)

eRad
10-12-2004, 10:00 AM
you could always append the VB code to a string and then just response.write(thestring) wherever you want it

afterburn
10-12-2004, 10:21 AM
You need to look at the WebControls, and the way events fire during execution. More so how state is held between all of them.

Like most people try to change the veiw state in the Page Load event. However it really never gets changed when the page is actually rendered to the client. Thats because its past the state in which you can modify it, you must modify it in Page PreRender event.

Anyways the way around your issue is to place labels on the page. Then assign the label.Text Property your values.

darktown
10-12-2004, 10:47 AM
I have several records from my select command.
I i used labels i am only going to get the last values of the last records.

I really just need to make a dynamic table that is presented in the body of my page. I want to make a link from the username to a more detailed page.

I don't think Labels are suited for that.

asp.net is really getting on my nerves PHP is waaay more easy. Everything in 1 stupid page, layout & code and it works. testing code with php was quicker, it takes really lots of time to test the code, if you cant to change vb code you need to stop and restart again...

really getting on my nerves..

I tried to response.write everything but i also need to write my loop in <script language=vb> tags and it doesn't do anything!


<script language=vb>
query = "select * from tbluserinformation order by Username"

If connOK = True Then
scmd.CommandText = query
scmd.Connection = myConnection
sdr = scmd.ExecuteReader()
Response.Write("<table width='100%'>")
While sdr.Read


bday = Split(sdr.GetString(6), "-")
birthday = bday(2) & "-" & bday(1) & "-" & bday(0)
</script>
<%
Response.Write("<tr><td>'" & sdr.GetString(1) & "'</td></tr>")
Response.Write("<tr><td>'" & sdr.GetString(2) & "'</td></tr>")
Response.Write("<tr><td>'" & sdr.GetString(3) & "'</td></tr>")
Response.Write("<tr><td>'" & sdr.GetString(4) & "'</td></tr>")
Response.Write("<tr><td>'" & sdr.GetString(5) & "'</td></tr>")
Response.Write("<tr><td>'" & sdr.GetString(7) & "'</td></tr>")
Response.Write("<tr><td>'" & sdr.GetString(8) & "'</td></tr>")
Response.Write("<tr><td>'" & sdr.GetString(9) & "'</td></tr>")
Response.Write("<tr><td>'" & sdr.GetString(10) & "'</td></tr>")
Response.Write("<tr><td>'" & birthday & "'</td></tr>")

%>
<script language=vb>
End While
Response.Write("</table>")
sdr.Close()
End If
</script>


doesn't work either. It says sdr.getstring(1) is empty (but in the database there are enoug records)
and in the source code i can see my vb script. i see my select command.... (is that normal?)

Another thing : i have to make all my variables that i delcared in the vb page Public so i can get to them in the aspx file. Could there be a security problem with it? I don't like public variables in general.

darktown
10-12-2004, 02:11 PM
renamed top.aspx to index.aspx

basically: made an iframe of it, and then it works :d haha!
maybe a tip for others if they get stuck ;)

code :

<HTML>
<HEAD>
<title>top</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<LINK href="Styles.css" type="text/css" rel="stylesheet">
<script type="text/javascript" language="JavaScript">

// begin of Animated Function in Statusbar

var hellotext = "Welcome at the dark side of Anime"
var thetext = "";
var started = false;
var step = 0;
var times = 1;

function welcometext() {
times--;
if (!times) {
if (!started) {
started = true;
window.status = hellotext;
setTimeout("anim()", 1);
}
thetext = hellotext;
}
}

function anim() {
step++;
if (step==7) step = 1;
if (step==1) window.status = '>===' + thetext + '===<';
if (step==2) window.status = '=>==' + thetext + '==<=';
if (step==3) window.status = '>=>=' + thetext + '=<=<';
if (step==4) window.status = '=>=>' + thetext + '<=<=';
if (step==5) window.status = '==>=' + thetext + '=<==';
if (step==6) window.status = '===>' + thetext + '<===';
setTimeout("anim()", 200);
}

// end of animated function in statusbar
</script>
</HEAD>
<body MS_POSITIONING="GridLayout" onload="welcometext();">
<table width="90%" height ="100%" cellspacing="0" cellpadding="0" align="center">
<tr width="100%" align ="center">
<!-- Show hostname & other options -->
<td class="small" align="left">&nbsp;</td>
<td class="small">Your Machinename : <% response.write(session("Hostname"))%>|&nbsp;|Succesfully Logged in as :<% response.write(session("Username"))%></td>
<td class="small" align="right"><% response.write(session("IP")) %></td>
</tr> <!-- End first row -->
<tr>
<td width="120" align="left" valign ="top"><!-- Left Menu Here -->
<br/>
<!-- Information:-->
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td height="26" class="itemHeader">Information</td>
</tr>
<tr>
<td width="120" class="menu"><a href='information.aspx?topic=profile' target='main'>&nbsp; ×My
Profile</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='information.aspx?topic=member' target='main'>&nbsp; ×MemberList</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='information.aspx?topic=staff' target='main'>&nbsp; ×Staff</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='information.aspx?topic=recruitment' target='main'>&nbsp;
×Recruitment</a></td>
</tr>
</table>
<br/>
<!-- General:-->
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td height="26" class="itemHeader">General</td>
</tr>
<tr>
<td width="120" class="menu"><a href='general.aspx?topic=history' target='main'>&nbsp; ×History</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='general.aspx?topic=links' target='main'>&nbsp; ×Links</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='general.aspx?topic=linkus' target='main'>&nbsp; ×Link Us?</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='general.aspx?topic=contact' target='main'>&nbsp; ×Contact</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='general.aspx?topic=forum' target='main'>&nbsp; ×Forum</a></td>
</tr>
</table>
<br/>
<!-- Media:-->
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td height="26" class="itemHeader">Media</td>
</tr>
<tr>
<td width="120" class="menu"><a href='media.aspx?topic=sound' target='main'>&nbsp; ×sound</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='media.aspx?topic=galleries' target='main'>&nbsp; ×galleries</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='media.aspx?topic=wallpapers' target='main'>&nbsp; ×wallpapers?</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='media.aspx?topic=amv' target='main'>&nbsp; ×amv</a></td>
</tr>
</table>
<br/>
<!-- reviews:-->
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td height="26" class="itemHeader">Reviews</td>
</tr>
<tr>
<td width="120" class="menu"><a href='reviews.aspx?topic=anime' target='main'>&nbsp; ×anime</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='reviews.aspx?topic=games' target='main'>&nbsp; ×games</a></td>
</tr>
</table>
<br/>
<!-- Webmaster:-->
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td height="26" class="itemHeader">Webmaster</td>
</tr>
<tr>
<td width="120" class="menu"><a href='webmaster.aspx?topic=php' target='main'>&nbsp; ×PHP</a></td>
</tr>
<tr>
<td width="120" class="menu"><a href='webmaster.aspx?topic=asp' target='main'>&nbsp; ×Asp.net</a></td>
</tr>
</table>
<br/>
</td> <!-- End Left Menu: -->
<td valign="top" align="center" > <!-- Main Start Here: -->
<br/>
<iframe class="iframe" style="BACKGROUND-COLOR: blue" id="main" name="main" src="main.aspx" width="90%" height="100%" frameborder="0"></iframe>
</td>

<!--#include file="bottum.aspx"-->

afterburn
10-12-2004, 04:13 PM
Look at HTML controls.... Table is one of them...
You can add it dynamically to the page. You might have to do

Page.FindControl("Name").Add()

where name is the Id of the Form. or you can do

Page.Controls.AddAt(1,tbl);