mixing HTML and VB in NET?

Joined
Jan 22, 2003
Messages
22
Location
Indiana, USA
So like everyone knows in classic ASP you can mix HTML and the VBScript. Is this not possible in .NET? Im needing to create a table that has a header and there are rows created based on an integer. Before I would just wrte the first row (header) of the table and then loop through the int and create that many rows below. Well how can I replicate that in .NET? Would I need to create two functions lets say and call those somehow? Im a bit lost on how much you can mix HTML and VB in .NET.

Thanks.
 
Also, can you use the DataGrid with form elements? Like if I wanted to read a table, put it into a datagrid but have some of the fields be a select box...is that possible? Or is the DataGrid just for displaying results?
 
You can easily use HTML table (tags)....

Create and display a Label or Panel, and just do this...

Code:
Label1.Text = "<table><tr><td>Something</td> .....etc..."
 
Well what if I wanted to create drop downs populated from a database? All of the fields are either dropdowns or text boxes. Ive been reading up on using code behind so do this, but is there an advantage to code behind for something like this? Im in my second week of .Net, and this seems to be the last of the big issues Im having.

All I want to to is be able to write out a table with n rows and have the form elements populate correctly. The data population from the table will be the next thing, but first Id like to be able just to create the correct amout of rows with one header.

Thanks!
 
With the above example I use the Code-Behind method...
You can populate an array with the data from a DB and then loop through the array to generate the <td> tags.

For a dropdown you can use the same method or if you need to handle events, use a DropDownList (web control) and bind the data using a Dataset.
 
You should use the .NET way (Code behind), but ASP.NET still supports the ever so familiar
<% myFunction(Butt, Boots) %>
or
<% =myValue%>

Difference is, if you want your functions then you have to define them and update something else on the page... The sample below should be how you would update a table with info from a database (does not show connection string, etc.)

So, you really DONT want to mix html and vb MOST of the time. This also helps to encapsulate your data. So if you use a code behind and these methods, you could distribut your .aspx page and a .dll --- Then your code would be protected.

ie:

<script language="vb" runat="server">
Dim ds As New DataSet
Dim dg As Datagrid
dg.DataSource = ds
dg.DataBind()
</script>


<html>

<asp:dg runat="server">

</html>
 
It seem to be more complicated compare with classic ASP...

In ASP.NET, we can either use code-behind or classic ASP method to program our ASP.NET application. Did anyone test the speed?
For this example of bang head here, use code-behind is faster or non-code-behind?
 
Back
Top