This is a migrated thread and some comments may be shown as answers.

Programatic Grid Creation Paging Problem

2 Answers 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bruce
Top achievements
Rank 1
Bruce asked on 09 Mar 2009, 11:23 PM
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 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Mar 2009, 06:08 AM
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
0
Bruce
Top achievements
Rank 1
answered on 10 Mar 2009, 12:07 PM
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

Tags
Grid
Asked by
Bruce
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Bruce
Top achievements
Rank 1
Share this question
or