Hi ,
I Have a ultrawebgrid with paging and sorting on server.
I am filling the grid using a datareader on a button click event.
Now once the data is filled in the grid , and if the button is clicked again then the data reloads without any problem but ,
If i fill the grid and then sort it (By clicking on the column header) and then if i reload the grid (by pressing the button) the the bind data throws an exception !!!
Can anybody tell me how this can be avoided ???Or why the grid is behaving in this manner ??
I don't know if I can help, but it would be useful if I knew what exception was being thrown, and could look at the code that binds the grid and that handles the button-click event.
Code To Bind the data
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Dim dr As SqlDataReader = Nothing
Params(0).Value = userinfo.GetValue(APPR.UserID).ToString
Params(1) = New SqlParameter("@sDate", SqlDbType.VarChar, 10)
Params(2).Value = userinfo.GetValue(APPR.HierarchyLevel)
Params(3).Value = whereqry
Dim errmsg As String = Nothing
If Connect_SQLDataReader(dr, "expt_show", errmsg, Params, CommandType.StoredProcedure) = False Then
Exit Try
End If
Me.ExptGrid.DataBind()
Me.UpdatePanel4.Update()
I have written Some code[setting the header Captions of the columns and filling values in the value lists of some columns] in the initialize layout. The Excecution runs fine before sorting !! After sorting when the same button is clicked.
DataBind is Called.
Object reference not set to an instance of an object.
Any ideas ???
Here is the stack trace !!!
--------------------
at Infragistics.WebUI.UltraWebGrid.UltraGridColumn.get_SortingAlgorithmResolved()
at Infragistics.WebUI.UltraWebGrid.RowsCollection.Sort()
at Infragistics.WebUI.UltraWebGrid.UltraWebGrid.SortGroupRows(RowsCollection rows)
at Infragistics.WebUI.UltraWebGrid.UltraWebGrid.PerformGroupRows()
at Infragistics.WebUI.UltraWebGrid.DBBinding.BindList(IEnumerable datasource)
at Infragistics.WebUI.UltraWebGrid.DBBinding.DataBind(Object dataSource, String dataMember)
at Infragistics.WebUI.UltraWebGrid.UltraWebGrid.DataBind()
---------------------
Is there some way i can reset the sort before binding the data ???
Thanks For ur response !! But unfortunately i cannot use The initializeDataSource event as it does not suit the requiements !!
I am not using any xml feature of the grid !! i am binding the grid on a button click event based on certain parameters selected by the user like date, dropdownlist etc. To be precise the end user will do the following to see\fill the data in the grid !!
-------------------------------------------------------------------------------------------
1.Select a date [from the calendar control] .
2. a node from a tree
3.then click the button to fill the grid [will will be on the basis of the selection ]
5. he can sort the data by clicking on the header.
4.He can change the selection [for eg : a different date] and again click the button to reload the grid based on the new selection
[Here i am again giving a datasource [datareader] to the grid]
--------------------------------------------------------------------------------------------
I will Re - Explain my problem here , along with one more issue that i have found !!
---------------------------------------------------------------------------------------------
Now the grid works fine but fails in this senario..
The user makes his selection and loads the grid !
He then sorts it by clicking on a column header
And when he changes his selection and reloads the grid it throws an exception !!
After seeing the error stack .. i think that the grid is not reseting the previous state !!
Same is the case with paging !!
Because during the initial load if there are 10 pages and if the after reload there are 3 pages then it still shows 10 pages !!!!!
So i need some thing that resets my grid !!!
Any Ideas ????????
It really depends on where in the page lifecycle you are binding the grid. What I can suggest is using the InitializeDataSource event - it gets automatically called whenever the grid needs data (could be after paging/sorting, in different stages of the page lifecycle event).
I found this blog post by lead technical evangelist Tony Lombardo extremely usefu when it comes to databinding and understanding how it works in UltraWebGridl:
http://blogs.infragistics.com/blogs/tony_lombardo/archive/2008/01/29/demystifying-infragistics-webgrid-databinding.aspx
You can also checkout the latest slide on the advanced grid databinding presentation from the Devscovery conference here:
http://blogs.infragistics.com/blogs/tony_lombardo/archive/2008/04/03/devscovery-slides.aspx