Programatic Grid Creation Paging Problem

3 posts, 0 answers
  1. Bruce
    Bruce avatar
    33 posts
    Member since:
    Oct 2006

    Posted 09 Mar 2009 Link to this post

    I created a grid using the code below.  The page loads fine and the first "next page" works.  But after that the "page"  links/buttons no longer work.  Any thoughts would be appreciated.

     

        Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            Dim PlaceHolder1 As PlaceHolder
            Dim RadGrid1 As RadGrid = New RadGrid
            Dim sql As String = "SELECT [ProductName] From Products order by ProductName"
            Dim GridDataSet As DataSet = CDSSQLFunctions.GetDataSet(sql)
            Dim boundColumn As GridBoundColumn
            RadGrid1.Skin = "Default"
            RadGrid1.Width = Unit.Percentage(100)
            RadGrid1.PageSize = 5
            RadGrid1.AllowPaging = True
            RadGrid1.AutoGenerateColumns = False
            RadGrid1.GroupingEnabled = True
            RadGrid1.ShowGroupPanel = True
            RadGrid1.MasterTableView.PageSize = 15

            BoundColumn = New GridBoundColumn
            boundColumn.DataField = "ProductName"
            boundColumn.HeaderText = "ProductName"
            RadGrid1.MasterTableView.Columns.Add(boundColumn)
            RadGrid1.DataSource = GridDataSet
            RadGrid1.DataBind()
            PlaceHolder1 = phGrid  '     <asp:PlaceHolder ID="phGrid" runat="server"></asp:PlaceHolder><br />
            PlaceHolder1.Controls.Add(RadGrid1)

        End Sub

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 10 Mar 2009 Link to this post

    Hi,

    If  you choose simple data-binding, you will need to assign data-source and rebind the grid after each operation (paging, sorting, editing, etc.) - this copies exactly MS DataGrid behavior. A suggestion would be to use the Advanced Data Binding technique method

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bruce
    Bruce avatar
    33 posts
    Member since:
    Oct 2006

    Posted 10 Mar 2009 Link to this post

    Thanks for the insight.  I modified the program as follows and it works fine:

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim PlaceHolder1 As PlaceHolder
            PlaceHolder1 = phGrid  '     <asp:PlaceHolder ID="phGrid" runat="server"></asp:PlaceHolder><br />
            Dim RadGrid1 As RadGrid = CType(PlaceHolder1.FindControl("RadGrid1"), RadGrid)
            Dim sql As String = "SELECT [ProductName] From Products order by ProductName"
            Dim GridDataSet As DataSet = CDSSQLFunctions.GetDataSet(sql)
            If CDSSQLFunctions.GetSqlError() <> "" Then
                lblMessage.Text = CDSSQLFunctions.GetSqlError()
                Exit Sub
            End If
            RadGrid1.DataSource = GridDataSet
        End Sub
        Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            Dim PlaceHolder1 As PlaceHolder
            Dim RadGrid1 As RadGrid = New RadGrid
            RadGrid1.ID = "RadGrid1"  ' Must assign an  ID so the grid can be found
            Dim boundColumn As GridBoundColumn
            RadGrid1.Skin = "Office2007"
            RadGrid1.Width = Unit.Percentage(100)
            RadGrid1.PageSize = 5
            RadGrid1.AllowPaging = True
            RadGrid1.AutoGenerateColumns = False
            RadGrid1.GroupingEnabled = True
            RadGrid1.ShowGroupPanel = True
            RadGrid1.MasterTableView.PageSize = 15

            boundColumn = New GridBoundColumn
            boundColumn.DataField = "ProductName"
            boundColumn.HeaderText = "ProductName"
            RadGrid1.MasterTableView.Columns.Add(boundColumn)
            PlaceHolder1 = phGrid  '     <asp:PlaceHolder ID="phGrid" runat="server"></asp:PlaceHolder><br />
            PlaceHolder1.Controls.Add(RadGrid1)

        End Sub

Back to Top