473,513 Members | 8,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.Net has me confused, little help please

I'm new to .Net and all of its abilities so I hope this makes sense.

Basically I'm confused on when is the appropriate time to use web forms
controls vs. regular HTML.

For example in ASP (non-.Net) if I wanted to fill a list it may look
something like this:

-------START CODE
<%
Dim dataObj, arr, rs, hasRecs, i
Set dataObj = Server.CreateObject("MyDll.DataAccess")
Set rs = dataObj.ExecuteQuery("SELECT * FROM SomeTable")
hasRecs = Not rs.EOF
If hasRecs Then arr = rs.GetRows
Set rs = Nothing
%>

<select name="cboSomeList" style="width:200px;" class="comboBox">
<%If hasRecs Then
For i = 0 To UBound(arr, 2)%>
<option value="<%=arr(i, 0)%>><%=arr(i, 1)%>
<%Next
End If%>
</select>
-------END CODE

Pretty straight forward right? In the example above I filled a combo box,
but I could easily change the HTML in the loop to make it a table, or a
series of inputs for a form or whatever.

Now if I wanted to do something similar in ASP.Net, I have some choices to
make.

1) Use some sort of Web Form Control (DataList, DataGrid, Repeater, Table,
ListBox, ComboBox)
- I'm a little confused here because there seem to be numerous controls that
seem to do similar things.
- I can use the DataList (which I have tried to use) however the code is
kinda all over the place.
- I set all it's appropriate properties (I think).
- In the aspx.vb code I got a DataSet (from my new .Net DataAccess dll)
- Created a DataTable and added columns and rows to it
- Created a DataView which added the DataTable
- Finally bound the DataList to that DataView (anyone else find this a
little redundant? shouldn't I be able to just bind it to the DataSet?).
- After all that I noticed that I had to give it an ItemTemplate to use
(That Template Editor makes no sense to me).
- So I looked for examples and found this : <%#
DataBinder.Eval(Container.DataItem, "ColumnName")%>
- However the result is a list with only 1 column.....??? The DataView that
the DataList is supposedly bound to has a DataTable with numerous columns,
what gives?
- It's that damn ItemTemplate I suspect, so what can I do to have multiple
columns?
- It almost looks like I need to concatenate the different columns (with
alignment spacing to format the columns)
- If that's the case what is the point of the DataList? Should I have saved
myself some time and coded it like I did in my example from above (from
non-.Net)?
- Is there any web form control that looks like the ListView from VB 6?
That would be nice.

2) Should I even bother coding the aspx.vb page or just code everything on
the HTML side with <% and %>?
- It looks like the aspx.vb page is good for doing event handling code, but
I'm confused about where to put my initial "page building" code.
- In fact, the DataList examples that I have seen all the coding is done on
the aspx page (which might be so people can copy & paste the example I
suspect).

3) Should I even use the Web Form controls?
- They seem nice but are also kind of restricted (or at least at first
glance).
- If I wanted to create a list from data that has multiple columns and rows
which might have text boxes in certain cells what should I use?
- Can I highlight the row by changing the background color during
ommouseover and onmouseout events with Web Form Controls? How? There are
no <tr>'s to add that code to.
Any help would be appreciated. I basically just want some general
guidelines to follow about when it's appropriate to use Web Form Controls vs
classic ASP style code. In your applications do you normally use these
controls? Is most of your server-side code (or all...) done on the aspx
page or the aspx.vb page?

Thanks,
Dan
Nov 17 '05 #1
2 2041
"Daniel" <dh******@data2you.net> wrote in message
news:OT**************@tk2msftngp13.phx.gbl...
I'm new to .Net and all of its abilities so I hope this makes sense.

Basically I'm confused on when is the appropriate time to use web forms
controls vs. regular HTML.

For example in ASP (non-.Net) if I wanted to fill a list it may look
something like this:

-------START CODE
<%
Dim dataObj, arr, rs, hasRecs, i
Set dataObj = Server.CreateObject("MyDll.DataAccess")
Set rs = dataObj.ExecuteQuery("SELECT * FROM SomeTable")
hasRecs = Not rs.EOF
If hasRecs Then arr = rs.GetRows
Set rs = Nothing
%>

<select name="cboSomeList" style="width:200px;" class="comboBox">
<%If hasRecs Then
For i = 0 To UBound(arr, 2)%>
<option value="<%=arr(i, 0)%>><%=arr(i, 1)%>
<%Next
End If%>
</select>
-------END CODE

Pretty straight forward right? In the example above I filled a combo box,
but I could easily change the HTML in the loop to make it a table, or a
series of inputs for a form or whatever.
Sure, but you end up with a lot of code, right?

In .NET, you simply bind the control to a DataSet. It can be done with drag
and drop, but you learn more with code. Let's go to work:

1. Slap a DropDownList control on your page. It will be called DropDownList1
2. Open up the CodeBehind page and write the following in your Page_Load
event:

'NOTE: Code not tested
If Not (Page.IsPostBack)
Dim conn As New SqlConnection(connStringHere)
Dim cmd As New SqlCommand(SqlString,conn)

Dim dr As New DataReader()

conn.Open()
Dim dr As New DataReader = cmd.ExecuteReader()

DropDownList1.DataSource = dr
DropDownList1.DataValueField = "ID"
DropDownList1.DataTextField = "Description"
DropDownList1.DataBind()

conn.Close()
End If

Less code, and .NET handles the binding for you. It does require a change in
thinking, however.

Now if I wanted to do something similar in ASP.Net, I have some choices to make.

1) Use some sort of Web Form Control (DataList, DataGrid, Repeater, Table,
ListBox, ComboBox)
Best usage:
DataList - list of items (one column) - can be kludged to do otherwise,
however
DataGrid - spreadsheet, may be sortable, pageable and editable
Repeater - Working with complex HTML
Table - CodeBehind creation of grid, otherwise, set table up in repeater
ListBox - Multiple item selection box
DropDownList - Single item drop down

The binding is fairly similar for each control, except the Repeater, which
is late bound.
- I'm a little confused here because there seem to be numerous controls that seem to do similar things.
- I can use the DataList (which I have tried to use) however the code is
kinda all over the place.
Shouldn't be, if you are using it correctly. With the above sample, you
simple change it to:

DataList1.DataSource = dr

And bind the columns declaratively in the HTML code in your ASPX page.
- I set all it's appropriate properties (I think).
- In the aspx.vb code I got a DataSet (from my new .Net DataAccess dll)
- Created a DataTable and added columns and rows to it
- Created a DataView which added the DataTable
- Finally bound the DataList to that DataView (anyone else find this a
little redundant? shouldn't I be able to just bind it to the DataSet?).
- After all that I noticed that I had to give it an ItemTemplate to use
(That Template Editor makes no sense to me).
- So I looked for examples and found this : <%#
DataBinder.Eval(Container.DataItem, "ColumnName")%>
Late binding.
- However the result is a list with only 1 column.....??? The DataView that the DataList is supposedly bound to has a DataTable with numerous columns,
what gives?
DataList has to be kludged to get multiple columns. It is not designed for
multiple columns, but for a single column.
- It's that damn ItemTemplate I suspect, so what can I do to have multiple
columns?
Change to a DataGrid.
- It almost looks like I need to concatenate the different columns (with
alignment spacing to format the columns)
- If that's the case what is the point of the DataList? Should I have saved myself some time and coded it like I did in my example from above (from
non-.Net)?
DataLists are great for single columns, like a list of hyperlinks.
- Is there any web form control that looks like the ListView from VB 6?
That would be nice.
I forget what ListView looks like (sorry), but you can use a DataGrid for
multiple columns, or use a Repeater for fairly complex HTML output.
2) Should I even bother coding the aspx.vb page or just code everything on
the HTML side with <% and %>?
Depends on the outcome desired. In general, I try to put code in the
CodeBehind page rather than in the ASPX page using <% %>. With late binding,
you end up using a <%# %> construct, so it cannot be completely avoided
without altering architecture.
- It looks like the aspx.vb page is good for doing event handling code, but I'm confused about where to put my initial "page building" code.
Page_Load event. If you need to dynamically add controls, use a container
object, like a Panel. You can then do something like:

Panel1.Controls.Add(MyControl)
- In fact, the DataList examples that I have seen all the coding is done on the aspx page (which might be so people can copy & paste the example I
suspect).
Or the fact that the first authors wrote their ASP.NET code like a new form
of ASP code. Most of the early books really sucked, and many people got
their examples from these books.
3) Should I even use the Web Form controls?
I would say yes, if you change your methodology from COM (ASP) to .NET
(ASP.NET), you will see that this is good advice. As long as you are
thinking ASP, the controls are confusing.
- They seem nice but are also kind of restricted (or at least at first
glance).
There are some restrictions, but you can overcome them by writing your own
HTML in a Repeater. You can also create your own classes that are derived
(subclassed) from the controls classes, if you find that they are restricted
too much. Derived classes are outside of your league right now, but you will
get there if you perservere.
- If I wanted to create a list from data that has multiple columns and rows which might have text boxes in certain cells what should I use?
DataGrid or Repeater. If the person is editing many rows at once, you would
be better suited with a Repeater, as it is more flexible. It is also more
difficult to set up (time consuming might be a better term here).
- Can I highlight the row by changing the background color during
ommouseover and onmouseout events with Web Form Controls? How? There are
no <tr>'s to add that code to.
With a Repeater, you can make the ItemTemplate have your tr tags and give
them an id by concatenating the ID field in your DataTable with a word that
you can uniquely find the TR from. From there it is a matter of matching the
JavaScript with the tag ID.
Any help would be appreciated. I basically just want some general
guidelines to follow about when it's appropriate to use Web Form Controls vs classic ASP style code. In your applications do you normally use these
controls? Is most of your server-side code (or all...) done on the aspx
page or the aspx.vb page?


Initially, I coded everything by hand. I then switched to C# to get out of
the VB mindset, so I would learn the new paradigm. I now use the controls to
save tons of time. After I learned the methodology, I switched back and
forth from C# to VB. My biggest hurdle was mentally tying the syntax to the
methodology. It sounds like this is a hurdle to you, as well.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
Nov 17 '05 #2
Thanks for the help.

I'll look into using the Repeater, hopefully that will be able to do what I
need it to do. It sounds like almost all of your server-side coding is done
with the ASPX.VB (or "code-behind") page, which is where I first expected
(and wanted) most code to be. I was getting a little worried as the code
started appearing everywhere for a simple list, but it seems that was
because I was using the wrong Web Form control and trying to bend it to fit
my needs.

Thanks,
Dan

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in
message news:ew**************@TK2MSFTNGP09.phx.gbl...
"Daniel" <dh******@data2you.net> wrote in message
news:OT**************@tk2msftngp13.phx.gbl...
I'm new to .Net and all of its abilities so I hope this makes sense.

Basically I'm confused on when is the appropriate time to use web forms
controls vs. regular HTML.

For example in ASP (non-.Net) if I wanted to fill a list it may look
something like this:

-------START CODE
<%
Dim dataObj, arr, rs, hasRecs, i
Set dataObj = Server.CreateObject("MyDll.DataAccess")
Set rs = dataObj.ExecuteQuery("SELECT * FROM SomeTable")
hasRecs = Not rs.EOF
If hasRecs Then arr = rs.GetRows
Set rs = Nothing
%>

<select name="cboSomeList" style="width:200px;" class="comboBox">
<%If hasRecs Then
For i = 0 To UBound(arr, 2)%>
<option value="<%=arr(i, 0)%>><%=arr(i, 1)%>
<%Next
End If%>
</select>
-------END CODE

Pretty straight forward right? In the example above I filled a combo box, but I could easily change the HTML in the loop to make it a table, or a
series of inputs for a form or whatever.
Sure, but you end up with a lot of code, right?

In .NET, you simply bind the control to a DataSet. It can be done with

drag and drop, but you learn more with code. Let's go to work:

1. Slap a DropDownList control on your page. It will be called DropDownList1 2. Open up the CodeBehind page and write the following in your Page_Load
event:

'NOTE: Code not tested
If Not (Page.IsPostBack)
Dim conn As New SqlConnection(connStringHere)
Dim cmd As New SqlCommand(SqlString,conn)

Dim dr As New DataReader()

conn.Open()
Dim dr As New DataReader = cmd.ExecuteReader()

DropDownList1.DataSource = dr
DropDownList1.DataValueField = "ID"
DropDownList1.DataTextField = "Description"
DropDownList1.DataBind()

conn.Close()
End If

Less code, and .NET handles the binding for you. It does require a change in thinking, however.

Now if I wanted to do something similar in ASP.Net, I have some choices to
make.

1) Use some sort of Web Form Control (DataList, DataGrid, Repeater, Table, ListBox, ComboBox)


Best usage:
DataList - list of items (one column) - can be kludged to do otherwise,
however
DataGrid - spreadsheet, may be sortable, pageable and editable
Repeater - Working with complex HTML
Table - CodeBehind creation of grid, otherwise, set table up in repeater
ListBox - Multiple item selection box
DropDownList - Single item drop down

The binding is fairly similar for each control, except the Repeater, which
is late bound.
- I'm a little confused here because there seem to be numerous controls

that
seem to do similar things.
- I can use the DataList (which I have tried to use) however the code is
kinda all over the place.


Shouldn't be, if you are using it correctly. With the above sample, you
simple change it to:

DataList1.DataSource = dr

And bind the columns declaratively in the HTML code in your ASPX page.
- I set all it's appropriate properties (I think).
- In the aspx.vb code I got a DataSet (from my new .Net DataAccess dll)
- Created a DataTable and added columns and rows to it
- Created a DataView which added the DataTable
- Finally bound the DataList to that DataView (anyone else find this a
little redundant? shouldn't I be able to just bind it to the DataSet?).
- After all that I noticed that I had to give it an ItemTemplate to use
(That Template Editor makes no sense to me).
- So I looked for examples and found this : <%#
DataBinder.Eval(Container.DataItem, "ColumnName")%>


Late binding.
- However the result is a list with only 1 column.....??? The DataView

that
the DataList is supposedly bound to has a DataTable with numerous columns, what gives?


DataList has to be kludged to get multiple columns. It is not designed for
multiple columns, but for a single column.
- It's that damn ItemTemplate I suspect, so what can I do to have multiple columns?


Change to a DataGrid.
- It almost looks like I need to concatenate the different columns (with
alignment spacing to format the columns)
- If that's the case what is the point of the DataList? Should I have

saved
myself some time and coded it like I did in my example from above (from
non-.Net)?


DataLists are great for single columns, like a list of hyperlinks.
- Is there any web form control that looks like the ListView from VB 6?
That would be nice.


I forget what ListView looks like (sorry), but you can use a DataGrid for
multiple columns, or use a Repeater for fairly complex HTML output.
2) Should I even bother coding the aspx.vb page or just code everything on the HTML side with <% and %>?


Depends on the outcome desired. In general, I try to put code in the
CodeBehind page rather than in the ASPX page using <% %>. With late

binding, you end up using a <%# %> construct, so it cannot be completely avoided
without altering architecture.
- It looks like the aspx.vb page is good for doing event handling code, but
I'm confused about where to put my initial "page building" code.


Page_Load event. If you need to dynamically add controls, use a container
object, like a Panel. You can then do something like:

Panel1.Controls.Add(MyControl)
- In fact, the DataList examples that I have seen all the coding is done

on
the aspx page (which might be so people can copy & paste the example I
suspect).


Or the fact that the first authors wrote their ASP.NET code like a new

form of ASP code. Most of the early books really sucked, and many people got
their examples from these books.
3) Should I even use the Web Form controls?
I would say yes, if you change your methodology from COM (ASP) to .NET
(ASP.NET), you will see that this is good advice. As long as you are
thinking ASP, the controls are confusing.
- They seem nice but are also kind of restricted (or at least at first
glance).


There are some restrictions, but you can overcome them by writing your own
HTML in a Repeater. You can also create your own classes that are derived
(subclassed) from the controls classes, if you find that they are

restricted too much. Derived classes are outside of your league right now, but you will get there if you perservere.
- If I wanted to create a list from data that has multiple columns and rows
which might have text boxes in certain cells what should I use?


DataGrid or Repeater. If the person is editing many rows at once, you

would be better suited with a Repeater, as it is more flexible. It is also more
difficult to set up (time consuming might be a better term here).
- Can I highlight the row by changing the background color during
ommouseover and onmouseout events with Web Form Controls? How? There are no <tr>'s to add that code to.
With a Repeater, you can make the ItemTemplate have your tr tags and give
them an id by concatenating the ID field in your DataTable with a word

that you can uniquely find the TR from. From there it is a matter of matching the JavaScript with the tag ID.
Any help would be appreciated. I basically just want some general
guidelines to follow about when it's appropriate to use Web Form
Controls vs
classic ASP style code. In your applications do you normally use these
controls? Is most of your server-side code (or all...) done on the aspx
page or the aspx.vb page?
Initially, I coded everything by hand. I then switched to C# to get out of
the VB mindset, so I would learn the new paradigm. I now use the controls

to save tons of time. After I learned the methodology, I switched back and
forth from C# to VB. My biggest hurdle was mentally tying the syntax to the methodology. It sounds like this is a hurdle to you, as well.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1166
by: C CORDON | last post by:
I am verry confused about classes. I understand that classes can encapsulate properties, methods, events (don't know hoy to add events to a class), etc. I am confused with this: if you can...
6
1674
by: manochavishal | last post by:
Hi , Ihave this code to show binary of an integer. #include<stdio.h> #include<stdlib.h> typedef struct binary* binaryptr; typedef struct binary { int data;
26
4653
by: Dodger | last post by:
Okay, background... yes, I am another of those evil, spurned, damnable Perl mongers, but I'm not trying to start a flamewar, I'm juust tryung to understand something... I can write a script in...
1
1808
by: Dilip | last post by:
I am a little confused about the difference between SFINAE and unambiguous overload resolution set. For ex: template<typename Tvoid func(T); template<typename Tvoid func(T*); now, func<intis...
1
1265
by: shapper | last post by:
Hello, I need to create a data object to hold a number of records with 3 columns. A datatable would do. My problem is this: 1. I will use this as a GridView datasource. 2. I will need to...
4
1936
by: bryant058 | last post by:
cout<<"-Please enter the spacing:"; cin>>space; cout<<"-Please enter a string of length<70:"<<endl; getline(cin,s); ----------------------------------------------------------------- when...
3
1577
by: boris | last post by:
i want to learn a language and hav options between JAVA and DotNet languages.but i am totally confused abt what to do.as this forum is for DotNet only thats y i m askin y shud i preffer DotNet...
4
2001
by: mattmao | last post by:
I am moving onto the tough part in learning C:( First, about the declaration of a user defined structure: I found this syntax in my lecture notes: struct userinfo { char username; ...
1
1341
by: Stephen D Cook | last post by:
I am trying to tie a column in a database to a dropdown list, but having very little luck. The table is bound to the .aspx page via oledbadapter1 and oleconnection1, but when I try to create a...
0
7254
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.