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

NeedDataSource & Rebind()

3 Answers 261 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vidya
Top achievements
Rank 1
Vidya asked on 26 Aug 2011, 08:19 PM

Hi,
I have a grid like following.....I have given only 1 column but there are 10 similar columns which comes from DB..similar in the sense it is rendered similar way this one column is shown below.
ASPX page.

 

 

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="true" Width="1080px" AutoGenerateColumns="false" GridLines="Both" Skin="XYZ" EnableEmbeddedSkins="false">

 

 

 

<MasterTableView Width="1063px" TableLayout="Fixed" ItemStyle-Font-Names="Arial" ItemStyle-Font-Size="11px" AlternatingItemStyle-Font-Size="11px" AlternatingItemStyle-Font-Names="Arial" HeaderStyle-Font-Names="Arial" HeaderStyle-Font-Size="11px" CommandItemDisplay="None">
<Columns>
<telerik:GridTemplateColumn HeaderText="Name" HeaderStyle-HorizontalAlign="Center" HeaderStyle-CssClass="rgcItemName" ItemStyle-CssClass="rgcItemName">

 

 

 

<ItemTemplate> <%#Container.DataItem("name").ToString%> </ItemTemplate> </telerik:GridTemplateColumn>

 

 

 

</Columns>

 

 

 

 

</MasterTableView>

 

 

 

<ClientSettings><Scrolling AllowScroll="true" UseStaticHeaders="true" /></ClientSettings>

 

</telerik:RadGrid>

 

 

 

</telerik:RadAjaxPanel>

 

VB Page

 

Protected Sub RadGrid1_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource

 

GetData()

 

End Sub

 

 

 

 

 

Protected

 

Function GetData() As Object

 

 

 

Dim table2 As New DataTable()

 

 

Dim XYZSql As String

 

 

 

XYZSql = ""

 

 

 

Dim XYZComm As New OracleCommand

 

 

Dim XYZConn As New OracleConnection(SQLConnStr)

 

 

Dim adapter As OracleDataAdapter = New OracleDataAdapter

 

adapter.SelectCommand =

New OracleCommand(XYZSql, XYZConn)

 

XYZConn.Open()

 

Try

 

 

 

adapter.Fill(table2)

 

RadGrid1.DataSource = table2

 

Catch ex As Exception

 

---

 

 

 

 

Finally

 

 

 

XYZConn.Close()

 

XYZConn.Dispose()

OracleConnection.ClearPool(XYZConn)

 

End Try

 

 

Return table2

 

 

End Function

 

 

 

On my Page Init Event all i am doing is RadGrid1.DataSource = Nothing like below code snippet shows. I am not calling Radgrid.ReBind(). But the Data still rebinds.

 

 

 

 

 

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

 

 

RadGrid1.DataSource = Nothing

 

End

 

Sub

 

WORKING CASE: Everything works fine so far...grid binds and sorts perfectly......

 

HOWEVER CASE: If i put Radgrid1.Rebind() after RadGrid1.DataSource = Nothing my grid does not sort in proper manner. If try to sort Col 1, col 3 sorts or col 2 sorts. I have no sorting event  other than AllowSorting=True in the aspx page. I absolutely dont have any columns to not be visible. Why Does it not sort well if i have Rebind() method called in Page Init.
I happen to read this topic in the link given below.....
http://www.telerik.com/help/aspnet/grid/grdcommandsthatinvokerebindimplicitly.html


Does NeedDataSource implicitly call Rebind method and sort the grid in WORKING CASE. Where does it store the data and binds it to the grid every time i sort the grid. Does it store in Hard Disc memory? If you are going to give me a link for sorting will it have an answer to the Question i just asked about where does it store the data to bind the grid again and again for each sorting. WORKING CASE does not have a direct call to Rebind.

In my HOWEVER CASE I am making an explicit call to Rebind(). Is it messing up the automatic sorting and the grid does not sort well?

References for Radgrid in Master page looks like.....
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>

 

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">

</telerik:RadAjaxManager>

 

Your answer will help me greatly
Vidya

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 26 Aug 2011, 09:17 PM
Hello,

NOTE : Radgrid.Rebind() event call the NeedDataSource event.

Case 1 : When the page first time load.
page_init
page_load
grid_needdatasource
page_prerender

Case 2 : When you sort any column
page_init
page_load
grid_itemcommand  // check if command is sort command then set the sortcolumn and sortdirection (asc/desc)  and then radgrid.Rebind() automatically call by radgrid. ...and this radgrid.rebind() call the NeedDataSource.
grid_needdatasource
page_prerender

let me know if any concern.

Thanks,
Jayesh Goyani
0
Vidya
Top achievements
Rank 1
answered on 26 Aug 2011, 09:44 PM
Jayesh,

In my Working case or Case 1 i dont have a rebind method which fires the NeedDataSource Event. All i am doing in Page Init event is RadGrid1.Datasource = Nothing. That is what is surprising me since thursday evening. Where is the Radgrid Binding data from? Is the NeedDataSource Event calling the Rebind Implicitly.........But It has solved my sorting problem.
If i put a breakpoint the control goes to
1) Page Init
2) Page Load
3) NeedDataSource Event.

Thanks,
Vidya


0
Jayesh Goyani
Top achievements
Rank 2
answered on 26 Aug 2011, 09:51 PM
Hello,

NOTE :Radgrid.Rebind() event call the NeedDataSource event.

When page is load first time grid automatically called NeedDataSource event.

and

after sort command radgrid also call needdatasource event automatically.

please check below links and if possible than put debug or breack point in your code so you can easily get idea of this.
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/needdatasource/defaultcs.aspx .... please see description in it and see demo

http://www.telerik.com/help/aspnet/grid/radgrid-telerik.webcontrols.radgrid-needdatasource_ev.html






Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Vidya
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Vidya
Top achievements
Rank 1
Share this question
or