ASP.NET data binding slow?

A

aualias

I am rewriting a web page that was previously done with ColdFusion. It has
a DataGrid and one column in the DataGrid is a dropdown list which is the
same for all rows. The ItemDataBound code looks like this...



// _viewDestinations is created once and stored in the ViewState



Private Sub dgWantList_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgWantList.ItemDataBound

If e.Item.ItemType = ListItemType.Item Or _

e.Item.ItemType = ListItemType.AlternatingItem Then

Dim ctrl As Control = e.Item.FindControl("ddlDesignations")

If Not ctrl Is Nothing Then

Dim ddl As DropDownList = CType(ctrl, DropDownList)

ddl.DataSource = _viewDesignations

ddl.DataTextField = "the_text_field"

ddl.DataValueField = "the_value_field"

ddl.DataBind()

End If

End If

End Sub



The DataGrid loads very slowly, however the ColdFusion table loads quickly.
There may be other factors at work here - the two web pages are not on the
same server. I have no access to the ColdFusion code and do not know much
about ColdFusion.



The difference in load time is striking. However, the server that I am
developing on does not normally seem slow. There are 3 other dropdowns
(also asp:dropdownlists) in the DataGrid (in the table in the ColdFusion
page as well), but their values are hardcoded in the .aspx page.



My questions are...

1) Is there anything inherently wrong with the way I am creating the
DropDownList in the DataGrid?

2) Is it normal in this situation for an ASP.NET page to load slowly?

3) What can I do to speed up the page load?



Thanks.



David
 
S

Scott Allen

Hi aualias:

Does the performance improve to a reasonable level after the first
time you view the page? The first view can be notoriously slow because
of all the parsing, compiling, and JITing, and generaly "warm up" of
the application.
 
B

billmiami2

I would guess it's the view state for the datagrid and all of the drop
down lists you have. Take a look at the html for the asp.net page and
see how large your viewstate is. I'll bet that it's very big and that
would account for the difference in load times.

If this is the case, the resolution would be to turn the view state off
for those controls if you can or selectively for certain elements in
your datagrid. I also remember seeing an article in ASP.NET Pro that
described how to keep the viewstate on the server rather than in the
page itself.

Note that both datagrids and dropdowns are notorious for causing "page
bloat" when their viewstate is enabled. Unfortunately, many of the
datagrid's events won't fire if you turn off the view state. In the
case of the listbox (and I think the dropdown), you must keep the
viewstate on in order to remember the selected value across postbacks.
Unfortunately, the entire list is also saved in the viewstate and you
have no choice about it.

Bill E.
 
A

aualias

The good news is that I viewed the page this morning and the load time was
MUCH quicker than the last time I looked at it, so part of the problem is
the development server.

On the other hand, the load time was not great. As you suspected, the
ViewState is enormous, but I cannot turn it off for the DataGrid because I
will lose the user's selections.

I shall look for information on leaving the view state on the server. This
is not a high volume site, so I do not think that it would be a problem.
Perhaps I could store the DataGrid in the session object.

Thanks for your help.

David
 
A

aualias

Scott,

The load time is slow even after the first view. I think that Bill's
thoughts on the view state being huge is the main part of the problem.

Thanks.

David
 
P

Peter Laan

I am rewriting a web page that was previously done with ColdFusion. It
has
a DataGrid and one column in the DataGrid is a dropdown list which is the
same for all rows. The ItemDataBound code looks like this...
My questions are...

1) Is there anything inherently wrong with the way I am creating the
DropDownList in the DataGrid?

2) Is it normal in this situation for an ASP.NET page to load slowly?

3) What can I do to speed up the page load?
[/QUOTE][/QUOTE]

Check this page for ideas on how to reduce the viewstate:
http://www.codeproject.com/aspnet/DataGridViewState.asp

The basic idea is to turn off the viewstate on all rows. It works great if
you only neeed an id for the row that the user selected. If the user is also
able to edit the contents, perhaps it's possible to turn off the viewstate
for all rows except the row being edited.

Peter
 
A

aualias

Peter,

This is an interesting article. I'm not sure that I can use it for this
problem, but it is a good thing to know about.

This datagrid has a checkbox column and a series of dropdowns that the user
can edit. If they check several columns, then the data goes into the
database, so the data from each checked row has to be saved.

Realistically, I think that the old design of this page is not great. If I
cannot get the page to display reasonably quickly, then I will change the
design to something quicker and probably more intuitive for the user.

Thanks.

David
 
P

Peter Laan

aualias said:
Peter,

This is an interesting article. I'm not sure that I can use it for this
problem, but it is a good thing to know about.

This datagrid has a checkbox column and a series of dropdowns that the
user can edit. If they check several columns, then the data goes into the
database, so the data from each checked row has to be saved.

Realistically, I think that the old design of this page is not great. If
I cannot get the page to display reasonably quickly, then I will change
the design to something quicker and probably more intuitive for the user.

I think you can do even this without viewstate. All checkbox and dropdown
values will be sent to the sever. Just check the Request like this (for a
textbox):

string test = Request["dg:_ctl2:Textbox1"];
dg is the name of the DataGrid. ctl2 specifies the second row. Textbox1 is
the name of the control.

Peter
 
A

aualias

Peter,

I won't be able to get to it for a while, but this sounds very interesting.
If I can remove the DataGrid from the ViewState and still get at the
dropdown values, the page may load acceptably.

Thanks.

David



Peter Laan said:
aualias said:
Peter,

This is an interesting article. I'm not sure that I can use it for this
problem, but it is a good thing to know about.

This datagrid has a checkbox column and a series of dropdowns that the
user can edit. If they check several columns, then the data goes into
the database, so the data from each checked row has to be saved.

Realistically, I think that the old design of this page is not great. If
I cannot get the page to display reasonably quickly, then I will change
the design to something quicker and probably more intuitive for the user.

I think you can do even this without viewstate. All checkbox and dropdown
values will be sent to the sever. Just check the Request like this (for a
textbox):

string test = Request["dg:_ctl2:Textbox1"];
dg is the name of the DataGrid. ctl2 specifies the second row. Textbox1 is
the name of the control.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top