ASP.NET data binding slow?

Discussion in 'ASP .Net' started by aualias, Apr 30, 2005.

  1. aualias

    aualias Guest

    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
    aualias, Apr 30, 2005
    #1
    1. Advertising

  2. aualias

    Scott Allen Guest

    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.

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    On Sat, 30 Apr 2005 12:05:40 -0400, "aualias"
    <> wrote:

    >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
    >
    >
    >
    >
    >
    >
    >
    Scott Allen, Apr 30, 2005
    #2
    1. Advertising

  3. aualias

    Guest

    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.
    , Apr 30, 2005
    #3
  4. aualias

    aualias Guest

    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



    <> wrote in message
    news:...
    >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.
    >
    aualias, May 2, 2005
    #4
  5. aualias

    aualias Guest

    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



    "Scott Allen" <> wrote in message
    news:...
    > 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.
    >
    > --
    > Scott
    > http://www.OdeToCode.com/blogs/scott/
    >
    > On Sat, 30 Apr 2005 12:05:40 -0400, "aualias"
    > <> wrote:
    >
    >>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
    >>
    >>
    >>
    >>
    >>
    >>
    >>

    >
    aualias, May 2, 2005
    #5
  6. aualias

    Peter Laan Guest

    >> On Sat, 30 Apr 2005 12:05:40 -0400, "aualias"
    >> <> wrote:
    >>
    >>>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...
    >>>

    <snip>
    >>>
    >>>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?


    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
    Peter Laan, May 3, 2005
    #6
  7. aualias

    aualias Guest

    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


    "Peter Laan" <> wrote in message
    news:%23vYaFK%...
    >>> On Sat, 30 Apr 2005 12:05:40 -0400, "aualias"
    >>> <> wrote:
    >>>
    >>>>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...
    >>>>

    > <snip>
    >>>>
    >>>>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?

    >
    > 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
    >
    >
    aualias, May 3, 2005
    #7
  8. aualias

    Peter Laan Guest

    "aualias" <> wrote in message
    news:OJVtj6%...
    > 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
    Peter Laan, May 4, 2005
    #8
  9. aualias

    aualias Guest

    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" <> wrote in message
    news:...
    > "aualias" <> wrote in message
    > news:OJVtj6%...
    >> 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
    >
    >
    >
    >
    aualias, May 4, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jordan
    Replies:
    2
    Views:
    2,512
    Jordan
    Feb 10, 2004
  2. Lloyd Sheen

    Data Binding with ADO.NET and ASP.NET

    Lloyd Sheen, Jun 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    383
    Cowboy \(Gregory A. Beamer\) [MVP]
    Jun 30, 2004
  3. Replies:
    3
    Views:
    2,998
  4. HK
    Replies:
    3
    Views:
    425
  5. JcFx
    Replies:
    0
    Views:
    263
Loading...

Share This Page