|
-
Dec 11th, 2003, 09:32 PM
#1
Thread Starter
PowerPoster
Please help with optimizing.
Ok, this might be a simple question, but I have been taking a datarow that holds all the information for the page's controls and populating one control at a time. This is so inefficient, and I am wondering what you do.
With a Win Form app, I set the controls tag properties to the column name that the control gets populated with. This allows me to run each control through a loop to find its own data and populate itself. Then I just do a for each loop looping the controls through the procedure to match up the data. Obviously Web Apps don't have the tag, and the control collections seem to also be a little more complex than what I have encountered on a windows app.
Any suggestions?
Here is some sample code I use on each page to fill the controls:
Code:
Private Sub BindPoleDetails()
Dim dtPoleData As New DataTable
Dim boPole As New BOPole
Dim intID As Integer
Try
'Check for a querystring ID
intID = CType(Request.QueryString.Item("PoleID"), Integer)
dtPoleData = boPole.GetPole(intID)
'TODO:Extend the textbox to add tags.
If Not dtPoleData Is Nothing Then
If Not dtPoleData.Rows(0)("WO #") Is DBNull.Value Then
txtWorkOrderNum.Text = dtPoleData.Rows(0)("WO #")
End If
If Not dtPoleData.Rows(0)("Class") Is DBNull.Value Then
txtClass.Text = dtPoleData.Rows(0)("Class")
End If
If Not dtPoleData.Rows(0)("TRS") Is DBNull.Value Then
txtTownship.Text = dtPoleData.Rows(0)("TRS")
End If
If Not dtPoleData.Rows(0)("Service Address") Is DBNull.Value Then
txtServiceAddress.Text = dtPoleData.Rows(0)("Service Address")
End If
If Not dtPoleData.Rows(0)("Comments") Is DBNull.Value Then
txtComments.Text = dtPoleData.Rows(0)("Comments")
End If
If Not dtPoleData.Rows(0)("Install Date") Is DBNull.Value Then
txtInstallDate.Text = dtPoleData.Rows(0)("Install Date")
End If
If Not dtPoleData.Rows(0)("Mfr date") Is DBNull.Value Then
txtManufactureDate.Text = dtPoleData.Rows(0)("Mfr date")
End If
If Not dtPoleData.Rows(0)("Size") Is DBNull.Value Then
ddlSize.SelectedValue = dtPoleData.Rows(0)("Size")
End If
If Not dtPoleData.Rows(0)("Owner") Is DBNull.Value Then
ddlOwner.SelectedValue = dtPoleData.Rows(0)("Owner")
End If
If Not dtPoleData.Rows(0)("Mfr") Is DBNull.Value Then
ddlManufacturer.SelectedValue = dtPoleData.Rows(0)("Mfr")
End If
If Not dtPoleData.Rows(0)("Location") Is DBNull.Value Then
ddlCounty.SelectedValue = dtPoleData.Rows(0)("Location")
End If
If Not dtPoleData.Rows(0)("Type") Is DBNull.Value Then
ddlOwnerType.SelectedValue = dtPoleData.Rows(0)("Type")
End If
If Not dtPoleData.Rows(0)("InActive") Is DBNull.Value Then
cbInActive.Checked = dtPoleData.Rows(0)("InActive")
End If
If Not dtPoleData.Rows(0)("Rotten") Is DBNull.Value Then
chbRotten.Checked = dtPoleData.Rows(0)("Rotten")
End If
If Not dtPoleData.Rows(0)("RetireWO") Is DBNull.Value Then
txtRetireWONum.Text = dtPoleData.Rows(0)("RetireWO")
End If
If Not dtPoleData.Rows(0)("RetireDate") Is DBNull.Value Then
txtRetireDate.Text = dtPoleData.Rows(0)("RetireDate")
End If
If Not dtPoleData.Rows(0)("SequenceNumber") Is DBNull.Value Then
txtSequenceNumber.Text = dtPoleData.Rows(0)("SequenceNumber")
End If
End If
Catch ex As Exception
'No PoleID in the query string. Send user to the home page.
Response.Redirect("default.aspx")
End Try
End Sub
-
Dec 13th, 2003, 04:03 PM
#2
Thread Starter
PowerPoster
Nevermind, I reduced it to something like this:
Code:
Public dtPoleData As New DataTable
Private Sub BindPoleDetails()
Dim boPole As New BOPole
Dim intID As Integer
Try
'Check for a querystring ID
intID = CType(Request.QueryString.Item("PoleID"), Integer)
dtPoleData = boPole.GetPole(intID)
If Not dtPoleData Is Nothing Then
Page.DataBind()
End If
Catch ex As Exception
'No PoleID in the query string. Send user to the home page.
Response.Redirect("default.aspx")
End Try
End Sub
I did this by setting the text properties and such to things like so in the actual aspx page:
Code:
<asp:textbox id="txtWorkOrderNum" runat="server" Width="100%" Text='<%# dtPoleData.Rows(0)("WONum") %>'></asp:textbox>
Seems to work well, I don't know if it is optimized, but there is less back end code to write, and a any web designer could change the data bindings at any time which allows more flexibility if the underlying data structure changes.
If anyone has any suggestions for me, please do tell.
-
Dec 14th, 2003, 09:52 AM
#3
I wonder how many charact
Well I'm slightly new to ASP.NET, and I have a different design issues than you.
But:
We simply use a datareader, and simply connect to the database on the page creation, and populate the controls that way.
VB Code:
if not dr(0) is DbNull.Value then myText = ctype(dr(0),string)
Ordinal lookups are roughly 15x faster.. and the datareader is quite faster than creating a datatable to hold the data.
Now, like I said, I don't know your design goals, so all of that may make little sense to you if you are caching your pages.
-
Dec 14th, 2003, 11:38 AM
#4
Hyperactive Member
Ordinal lookups are roughly 15x faster
Where'd you get that from? I'm not disagreeing, I just want to see the code/article/msdn doc that shows that difference.
-
Dec 14th, 2003, 11:46 AM
#5
Thread Starter
PowerPoster
Originally posted by nemaroller
Well I'm slightly new to ASP.NET, and I have a different design issues than you.
But:
We simply use a datareader, and simply connect to the database on the page creation, and populate the controls that way.
VB Code:
if not dr(0) is DbNull.Value then myText = ctype(dr(0),string)
Ordinal lookups are roughly 15x faster.. and the datareader is quite faster than creating a datatable to hold the data.
Now, like I said, I don't know your design goals, so all of that may make little sense to you if you are caching your pages.
Agreed. The code above is more of a starting point. I haven't even tried to optimize it for the web. Normally I use datareaders for everything. They just make sense because they are super fast.
For web work, ALWAYS try to use a datareader than a datatable/dataset if you can.
-
Dec 14th, 2003, 01:22 PM
#6
I wonder how many charact
Originally posted by pvb
Where'd you get that from? I'm not disagreeing, I just want to see the code/article/msdn doc that shows that difference.
Just from experience...
On a high level, its like comparing the performance of a pointer
vs
the performance of a function that takes a string, and transverses across all datacolumns to find a match. And the code that runs to determine if one string = another string.
vs
VB Code:
'also realize the more columns you have, the longer this takes.
'and the longer the names of your columns, the longer this takes
'and the more times you use mytable.columns("") to set all the
'data in your table, the time to complete keeps multiplying.
Protected Function findOrdinalfromString(targetString) As Integer
Dim match As Boolean = False
For j = 0 To me.datacolumns.count-1
For i = 0 To me.datacolumn(j).ColumnName.Length
If Not somedatacolumnheaderstring.char[i] is targetstring.char[i]
Exit For
End If
If i = me.datacolumn(j).ColumnName.Length - 1 Then match = True
Next
If match return j
Next
Throw 'error
End Function
Last edited by nemaroller; Dec 14th, 2003 at 01:28 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|