Refreshing a DataList

Discussion in 'ASP .Net Web Controls' started by Nathan Sokalski, Jan 3, 2007.

  1. I have a DataList control that I want users to be able to sort the data in
    by clicking 1 of 3 buttons. The function I have created to do this is as
    follows:


    Private Sub SortPoems(ByVal sortby As String)
    Dim ratedpoems As New DataTable
    Dim sqltext As String = "SELECT * FROM poemratings ORDER BY "

    Select Case sortby
    Case "title"
    sqltext &= "title"
    Case "rating"
    sqltext &= "(totalpoints/timesrated),timesrated,title"
    Case "timesrated"
    sqltext &= "timesrated,(totalpoints/timesrated),title"
    End Select
    Dim dataadapterSelect As New System.Data.OleDb.OleDbDataAdapter(sqltext,
    System.Configuration.ConfigurationManager.AppSettings("connectionstring"))
    dataadapterSelect.Fill(ratedpoems)
    Me.datRatings.DataSource = ratedpoems
    Me.datRatings.DataBind()
    End Sub


    When the page first loads, I call

    Me.SortPoems("title")

    from Page_Load, which works fine, but when I try to call it a second time
    using one of the buttons it does not work. However, if I call it twice in
    Page_Load, it does work when I call it with the buttons. Why is this? What
    is it that calling it a second time in Page_Load does that allows me to call
    it with the buttons? I am using Microsoft Access as my database, and I am
    using ASP.NET 2.0. Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Jan 3, 2007
    #1
    1. Advertising

  2. Nathan Sokalski

    Goofy Guest

    1.) When you say you cannot call it from one of the buttons, do you mean

    a.) That the code is not executed
    b) That the code is executed but does not work as expected.?

    2.) If 1a) Then you need to look at the handler for the button , if 1b)
    then you need to review if the DataList is being bound somehere else in you
    code .


    3.) The order the events fire in are important, look at your event handlers
    for the page events and make sure you are not rebinding the control to
    another or an unpopulated data source.


    HTH






    "Nathan Sokalski" <> wrote in message
    news:%...
    >I have a DataList control that I want users to be able to sort the data in
    >by clicking 1 of 3 buttons. The function I have created to do this is as
    >follows:
    >
    >
    > Private Sub SortPoems(ByVal sortby As String)
    > Dim ratedpoems As New DataTable
    > Dim sqltext As String = "SELECT * FROM poemratings ORDER BY "
    >
    > Select Case sortby
    > Case "title"
    > sqltext &= "title"
    > Case "rating"
    > sqltext &= "(totalpoints/timesrated),timesrated,title"
    > Case "timesrated"
    > sqltext &= "timesrated,(totalpoints/timesrated),title"
    > End Select
    > Dim dataadapterSelect As New
    > System.Data.OleDb.OleDbDataAdapter(sqltext,
    > System.Configuration.ConfigurationManager.AppSettings("connectionstring"))
    > dataadapterSelect.Fill(ratedpoems)
    > Me.datRatings.DataSource = ratedpoems
    > Me.datRatings.DataBind()
    > End Sub
    >
    >
    > When the page first loads, I call
    >
    > Me.SortPoems("title")
    >
    > from Page_Load, which works fine, but when I try to call it a second time
    > using one of the buttons it does not work. However, if I call it twice in
    > Page_Load, it does work when I call it with the buttons. Why is this? What
    > is it that calling it a second time in Page_Load does that allows me to
    > call it with the buttons? I am using Microsoft Access as my database, and
    > I am using ASP.NET 2.0. Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
     
    Goofy, Jan 3, 2007
    #2
    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. =?Utf-8?B?Q2hyaXMgRmluaw==?=

    RE: Refreshing DataList through user control

    =?Utf-8?B?Q2hyaXMgRmluaw==?=, Sep 3, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    500
    =?Utf-8?B?Q2hyaXMgRmluaw==?=
    Sep 3, 2004
  2. Nevyn Twyll
    Replies:
    8
    Views:
    1,916
  3. H5N1
    Replies:
    0
    Views:
    2,741
  4. Harlan Messinger

    Self-refreshing and non-self-refreshing controls

    Harlan Messinger, Aug 4, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    470
    =?Utf-8?B?Y2xpY2tvbg==?=
    Aug 4, 2006
  5. Harlan Messinger

    Self-refreshing and non-self-refreshing controls

    Harlan Messinger, Aug 3, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    194
    Harlan Messinger
    Aug 3, 2006
Loading...

Share This Page