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.CreateOb ject("MyDll.Dat aAccess")
Set rs = dataObj.Execute Query("SELECT * FROM SomeTable")
hasRecs = Not rs.EOF
If hasRecs Then arr = rs.GetRows
Set rs = Nothing
%>
<select name="cboSomeLi st" style="width:20 0px;" 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.Data Item, "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 2 2060
"Daniel" <dh******@data2 you.net> wrote in message
news:OT******** ******@tk2msftn gp13.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.CreateOb ject("MyDll.Dat aAccess") Set rs = dataObj.Execute Query("SELECT * FROM SomeTable") hasRecs = Not rs.EOF If hasRecs Then arr = rs.GetRows Set rs = Nothing %>
<select name="cboSomeLi st" style="width:20 0px;" 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.IsPostBac k)
Dim conn As New SqlConnection(c onnStringHere)
Dim cmd As New SqlCommand(SqlS tring,conn)
Dim dr As New DataReader()
conn.Open()
Dim dr As New DataReader = cmd.ExecuteRead er()
DropDownList1.D ataSource = dr
DropDownList1.D ataValueField = "ID"
DropDownList1.D ataTextField = "Descriptio n"
DropDownList1.D ataBind()
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.DataS ource = 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.Data Item, "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!
*************** *************** *************** *************** **********
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.netNoS pamM> wrote in
message news:ew******** ******@TK2MSFTN GP09.phx.gbl... "Daniel" <dh******@data2 you.net> wrote in message news:OT******** ******@tk2msftn gp13.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.CreateOb ject("MyDll.Dat aAccess") Set rs = dataObj.Execute Query("SELECT * FROM SomeTable") hasRecs = Not rs.EOF If hasRecs Then arr = rs.GetRows Set rs = Nothing %>
<select name="cboSomeLi st" style="width:20 0px;" 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.IsPostBac k) Dim conn As New SqlConnection(c onnStringHere) Dim cmd As New SqlCommand(SqlS tring,conn)
Dim dr As New DataReader()
conn.Open() Dim dr As New DataReader = cmd.ExecuteRead er()
DropDownList1.D ataSource = dr DropDownList1.D ataValueField = "ID" DropDownList1.D ataTextField = "Descriptio n" DropDownList1.D ataBind()
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.DataS ource = 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.Data Item, "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! *************** *************** *************** *************** **********
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 encapsulate all this in a class, how do
you decide or when is it necessary to Dim x as new MyClass or when to use
Imports MyClass. Eather way you have access to all that is inside it.
If I make a class calld User and I want it to handle everything...
|
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;
|
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 Perl like so, and it's pretty to me (and the
using of the heredocs I think does defend perl against many arguments
withthe HTML being all escaped and explicit returns and stuff -- which
I can see... 'print "<p class=\"text\">stuff</p>\n";' is...
|
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 going to be ambiguous. Ok so far so good.
Now:
|
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 postback so I can Insert, Delete, Update records
| |
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 executeing,after i key in space=2,
the program show "-Please enter a string of length<70:"
then it stop,
why can't i continuing key in the string??
|
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 language
like C#.net over JAVA.I am intrested in software and somewhat in game
development.plz help.
|
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;
int age;
|
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 dataset from it and use one
column of the table, it doesnt work. Either I get an error saying the
type is not a recordset, or it just wont fill the combobox. Please
Help
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |