AutoGenerateColumns - DataGrid Paging

Discussion in 'ASP .Net Datagrid Control' started by Frank Walsh, May 9, 2005.

  1. Frank Walsh

    Frank Walsh Guest

    Hi,

    I am experiencing a problem with datagrid paging when I attempt to disable
    AutoGenerateColumns. My event handler for the pager will not fire, thus the
    paging does not occur. I really don't want to have to do 2 sql calls
    everytime someone wants to page which I have found will work ( removing the
    BindData only if not postback in the pageload function). Can anyone tell me
    if there is something I'm doing wrong here?

    Things I have tried to fix this problem:

    1.Enable and disabled Viewstate on the Datagrid - No Effect
    2.Override the LoadViewState Sub and called DefineDataGrid in it - No Effect
    3. Bound and Not Bound at the conclusion of DefineDataGrid Function - No
    Effect
    4. Called my define datagrid function in page load explicitely independent
    of postback or not - No Effect

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    If Not Page.IsPostBack Then

    BindData()

    End If

    End Sub



    Sub DefineDataGrid()

    DataGrid1.AllowPaging = True

    DataGrid1.PagerStyle.Mode = PagerMode.NumericPages

    DataGrid1.PageSize = 25

    Dim DataGridCol As BoundColumn

    DataGridCol = New BoundColumn

    With DataGridCol

    .HeaderText = "Report #"

    .. DataField = "ReportNum"

    End With

    DataGrid1.Columns.Add(DataGridCol)

    Me.DataGrid1.DataBind()

    End Sub



    Sub BindData()

    DefineDataGrid()

    STANDARD SQL STUFF HERE

    End Sub



    Sub PageIndexChanged_Click(ByVal sender As Object, ByVal e As
    DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged

    DataGrid1.CurrentPageIndex = e.NewPageIndex

    BindData()

    End Sub
    Frank Walsh, May 9, 2005
    #1
    1. Advertising

  2. Frank Walsh

    Brock Allen Guest

    Since you are adding a column dynamically, you'll have to make sure you recreate
    the column upon every postback somewhere in or prior to Page_Init. Is there
    a reason you can't just declare the column statically in the ASPX file?

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Hi,
    >
    > I am experiencing a problem with datagrid paging when I attempt to
    > disable AutoGenerateColumns. My event handler for the pager will not
    > fire, thus the paging does not occur. I really don't want to have to
    > do 2 sql calls everytime someone wants to page which I have found will
    > work ( removing the BindData only if not postback in the pageload
    > function). Can anyone tell me if there is something I'm doing wrong
    > here?
    >
    > Things I have tried to fix this problem:
    >
    > 1.Enable and disabled Viewstate on the Datagrid - No Effect
    > 2.Override the LoadViewState Sub and called DefineDataGrid in it - No
    > Effect
    > 3. Bound and Not Bound at the conclusion of DefineDataGrid Function -
    > No
    > Effect
    > 4. Called my define datagrid function in page load explicitely
    > independent
    > of postback or not - No Effect
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    >
    > If Not Page.IsPostBack Then
    >
    > BindData()
    >
    > End If
    >
    > End Sub
    >
    > Sub DefineDataGrid()
    >
    > DataGrid1.AllowPaging = True
    >
    > DataGrid1.PagerStyle.Mode = PagerMode.NumericPages
    >
    > DataGrid1.PageSize = 25
    >
    > Dim DataGridCol As BoundColumn
    >
    > DataGridCol = New BoundColumn
    >
    > With DataGridCol
    >
    > .HeaderText = "Report #"
    >
    > . DataField = "ReportNum"
    >
    > End With
    >
    > DataGrid1.Columns.Add(DataGridCol)
    >
    > Me.DataGrid1.DataBind()
    >
    > End Sub
    >
    > Sub BindData()
    >
    > DefineDataGrid()
    >
    > STANDARD SQL STUFF HERE
    >
    > End Sub
    >
    > Sub PageIndexChanged_Click(ByVal sender As Object, ByVal e As
    > DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
    >
    > DataGrid1.CurrentPageIndex = e.NewPageIndex
    >
    > BindData()
    >
    > End Sub
    >
    Brock Allen, May 9, 2005
    #2
    1. Advertising

  3. Frank Walsh

    Frank Walsh Guest

    Brock,

    I got your message regarding recreating the columns prior to Page_Init,
    could you tell me a function I could overload to do something like this. I
    do realize defining them in the ASPX file is an option but some of the
    columns I plan to add require a sql call themselves to decide what fields to
    put in a drop down list for that column.

    If you know a function I could overload to do this, or even a good example,
    I would greatly appreciate it.

    Thank You

    Frank Walsh


    "Brock Allen" <> wrote in message
    news:...
    > Since you are adding a column dynamically, you'll have to make sure you
    > recreate the column upon every postback somewhere in or prior to
    > Page_Init. Is there a reason you can't just declare the column statically
    > in the ASPX file?
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    >> Hi,
    >>
    >> I am experiencing a problem with datagrid paging when I attempt to
    >> disable AutoGenerateColumns. My event handler for the pager will not
    >> fire, thus the paging does not occur. I really don't want to have to
    >> do 2 sql calls everytime someone wants to page which I have found will
    >> work ( removing the BindData only if not postback in the pageload
    >> function). Can anyone tell me if there is something I'm doing wrong
    >> here?
    >>
    >> Things I have tried to fix this problem:
    >>
    >> 1.Enable and disabled Viewstate on the Datagrid - No Effect
    >> 2.Override the LoadViewState Sub and called DefineDataGrid in it - No
    >> Effect
    >> 3. Bound and Not Bound at the conclusion of DefineDataGrid Function -
    >> No
    >> Effect
    >> 4. Called my define datagrid function in page load explicitely
    >> independent
    >> of postback or not - No Effect
    >> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    >> System.EventArgs) Handles MyBase.Load
    >>
    >> If Not Page.IsPostBack Then
    >>
    >> BindData()
    >>
    >> End If
    >>
    >> End Sub
    >>
    >> Sub DefineDataGrid()
    >>
    >> DataGrid1.AllowPaging = True
    >>
    >> DataGrid1.PagerStyle.Mode = PagerMode.NumericPages
    >>
    >> DataGrid1.PageSize = 25
    >>
    >> Dim DataGridCol As BoundColumn
    >>
    >> DataGridCol = New BoundColumn
    >>
    >> With DataGridCol
    >>
    >> .HeaderText = "Report #"
    >>
    >> . DataField = "ReportNum"
    >>
    >> End With
    >>
    >> DataGrid1.Columns.Add(DataGridCol)
    >>
    >> Me.DataGrid1.DataBind()
    >>
    >> End Sub
    >>
    >> Sub BindData()
    >>
    >> DefineDataGrid()
    >>
    >> STANDARD SQL STUFF HERE
    >>
    >> End Sub
    >>
    >> Sub PageIndexChanged_Click(ByVal sender As Object, ByVal e As
    >> DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
    >>
    >> DataGrid1.CurrentPageIndex = e.NewPageIndex
    >>
    >> BindData()
    >>
    >> End Sub
    >>

    >
    >
    >
    Frank Walsh, May 9, 2005
    #3
  4. Frank Walsh

    Brock Allen Guest

    I posted a sample recently. It's not exactly adding Columns to a DataGrid,
    but I don't see why it wouldn't work for you:

    http://groups-beta.google.com/group...450?q=brock dynamic controls viewstate&rnum=1

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Brock,
    >
    > I got your message regarding recreating the columns prior to
    > Page_Init, could you tell me a function I could overload to do
    > something like this. I do realize defining them in the ASPX file is an
    > option but some of the columns I plan to add require a sql call
    > themselves to decide what fields to put in a drop down list for that
    > column.
    >
    > If you know a function I could overload to do this, or even a good
    > example, I would greatly appreciate it.
    >
    > Thank You
    >
    > Frank Walsh
    >
    > "Brock Allen" <> wrote in message
    > news:...
    >
    >> Since you are adding a column dynamically, you'll have to make sure
    >> you recreate the column upon every postback somewhere in or prior to
    >> Page_Init. Is there a reason you can't just declare the column
    >> statically in the ASPX file?
    >>
    >> -Brock
    >> DevelopMentor
    >> http://staff.develop.com/ballen
    >>> Hi,
    >>>
    >>> I am experiencing a problem with datagrid paging when I attempt to
    >>> disable AutoGenerateColumns. My event handler for the pager will not
    >>> fire, thus the paging does not occur. I really don't want to have to
    >>> do 2 sql calls everytime someone wants to page which I have found
    >>> will work ( removing the BindData only if not postback in the
    >>> pageload function). Can anyone tell me if there is something I'm
    >>> doing wrong here?
    >>>
    >>> Things I have tried to fix this problem:
    >>>
    >>> 1.Enable and disabled Viewstate on the Datagrid - No Effect
    >>> 2.Override the LoadViewState Sub and called DefineDataGrid in it -
    >>> No
    >>> Effect
    >>> 3. Bound and Not Bound at the conclusion of DefineDataGrid Function
    >>> -
    >>> No
    >>> Effect
    >>> 4. Called my define datagrid function in page load explicitely
    >>> independent
    >>> of postback or not - No Effect
    >>> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    >>> System.EventArgs) Handles MyBase.Load
    >>> If Not Page.IsPostBack Then
    >>>
    >>> BindData()
    >>>
    >>> End If
    >>>
    >>> End Sub
    >>>
    >>> Sub DefineDataGrid()
    >>>
    >>> DataGrid1.AllowPaging = True
    >>>
    >>> DataGrid1.PagerStyle.Mode = PagerMode.NumericPages
    >>>
    >>> DataGrid1.PageSize = 25
    >>>
    >>> Dim DataGridCol As BoundColumn
    >>>
    >>> DataGridCol = New BoundColumn
    >>>
    >>> With DataGridCol
    >>>
    >>> .HeaderText = "Report #"
    >>>
    >>> . DataField = "ReportNum"
    >>>
    >>> End With
    >>>
    >>> DataGrid1.Columns.Add(DataGridCol)
    >>>
    >>> Me.DataGrid1.DataBind()
    >>>
    >>> End Sub
    >>>
    >>> Sub BindData()
    >>>
    >>> DefineDataGrid()
    >>>
    >>> STANDARD SQL STUFF HERE
    >>>
    >>> End Sub
    >>>
    >>> Sub PageIndexChanged_Click(ByVal sender As Object, ByVal e As
    >>> DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
    >>>
    >>> DataGrid1.CurrentPageIndex = e.NewPageIndex
    >>>
    >>> BindData()
    >>>
    >>> End Sub
    >>>
    Brock Allen, May 10, 2005
    #4
    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. Replies:
    0
    Views:
    613
  2. =?Utf-8?B?U2Vhblc=?=
    Replies:
    0
    Views:
    639
    =?Utf-8?B?U2Vhblc=?=
    Apr 10, 2007
  3. moondog
    Replies:
    0
    Views:
    551
    moondog
    Apr 12, 2007
  4. Emil O
    Replies:
    0
    Views:
    216
    Emil O
    Sep 2, 2003
  5. pietaster
    Replies:
    1
    Views:
    134
    Bernard O'Flynn
    Oct 28, 2003
Loading...

Share This Page