AutoGenerateColumns - DataGrid Paging

F

Frank Walsh

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
 
B

Brock Allen

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

Frank Walsh

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top