D
Daniel
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
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