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

RadGrid NeedDataSource Page load

15 Answers 1344 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ashwin Deshpande
Top achievements
Rank 1
Ashwin Deshpande asked on 02 Sep 2009, 12:04 PM
I do not want the RadGrid NeedDataSource to fire on Page Load Event instead i need to fire it on Search button Clickin My Form.
i need to Populate radgrid only after the input Control Data and Search button Click.
Please Help me...
are there any properties i am missing on??

Regards,
Ashwin

15 Answers, 1 is accepted

Sort by
0
Casey
Top achievements
Rank 1
answered on 02 Sep 2009, 12:13 PM
Ashwin,

Instead of populating the RadGrid on the NeedDataSource event, you could try assigning the DataSource in the Click event of your Search button.

protected void Button_Click(object sender, EventArgs e)  
    {  
        RadGrid1.DataSourceID = "DataSourceName";  
    } 

Casey
0
Vlad
Telerik team
answered on 02 Sep 2009, 12:15 PM
Hi Ashwin,

You do not have use NeedDataSource advanced data-binding if you do not want - you can use simple data binding.

Regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ashwin Deshpande
Top achievements
Rank 1
answered on 02 Sep 2009, 12:16 PM
Thanks for your reply,
But the Problem is that i Do Not want need datasource Event to be fired on Page load....By default while debugging after page load it goes to Needatasource code and executes the code.

Regards,
Ashwin
0
Casey
Top achievements
Rank 1
answered on 02 Sep 2009, 12:23 PM
Have you tried removing the below from the definition of the RadGrid? If your RadGrid still has a method attached to the OnNeedDataSource event, then it will execute the code. If you remove the OnNeedDataSource event from the RadGrid definition, no code should be executed.

OnNeedDataSource

 

="NeedDataSource"

 

0
Ashwin Deshpande
Top achievements
Rank 1
answered on 02 Sep 2009, 12:33 PM

Below is my Telerik Definition still it goes to NeedDatasource event

telerik

 

:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True"

 

 

Skin="Office2007" AllowFilteringByColumn="True" ShowStatusBar="True" PageSize="12"

 

 

Width="99%" >

 

 

<PagerStyle Mode="NextPrevNumericAndAdvanced" AlwaysVisible="true" />

 

 

<MasterTableView DataKeyNames="ACT_ID" EditMode="PopUp" AutoGenerateColumns="False"

 

 

Width="100%" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Add New Activity">

 

 

<CommandItemTemplate>

 

 

<table width="100%">

 

 

<tr>

 

 

<td style="text-align: left; width: 30%">

 

 

<img style="border: 0px" alt="" src="../../Images/Telerik%20Images/AddRecord.gif" />

 

 

<asp:LinkButton ID="btnAdd" Text="Add New Activity" CommandName="InitInsert" runat="server">

 

 

 

</asp:LinkButton>

 

 

</td>

 

 

<td style="text-align: center; width: 40%">

 

 

<asp:LinkButton runat="server" ID="LinkButton1" Text="Clear Filters" CommandName="ClearFilters" />

 

 

</td>

 

 

<td style="text-align: left; width: 30%">

 

 

<img style="border: 0px" alt="" src="../../Images/Telerik%20Images/Refresh.gif" />

 

 

<asp:LinkButton ID="btnRefresh" Text="Refresh" CommandName="Rebind" runat="server">

 

 

</asp:LinkButton>

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

 

</CommandItemTemplate>

 

0
Casey
Top achievements
Rank 1
answered on 02 Sep 2009, 12:41 PM
Do you have any code in your Page Load javascript function or Page Load in the codebehind that would fire the OnNeedDataSource event? If not, have you tried removing the code that you don't want executed to see if any errors are generated? Or instead of removing the code, move it into the method called by the OnClick event of the Search button and comment out the code that is being called during Page Load.

Casey
0
Ashwin Deshpande
Top achievements
Rank 1
answered on 02 Sep 2009, 02:09 PM
I removed everything from the Page Load even then also it goes to Radgrid NeedDataSource Command Event...
0
Ashwin Deshpande
Top achievements
Rank 1
answered on 02 Sep 2009, 02:19 PM
Take this Sample Code ..Even in this One also it goes to NeedDatasource event on page load.Please Suggest

aspx

<%

@ Page Language="VB" AutoEventWireup="false" CodeFile="RadGrid.aspx.vb" Inherits="RadGrid" %>

 

<%

@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

 

<!

 

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<

 

html xmlns="http://www.w3.org/1999/xhtml">

 

<

 

head runat="server">

 

 

<title>Untitled Page</title>

 

</

 

head>

 

<

 

body>

 

 

<form id="form1" runat="server">

 

 

<div>

 

 

<telerik:RadGrid ID="RadGrid1" runat="server">

 

 

</telerik:RadGrid>

 

 

</div>

 

 

</form>

 

</

 

body>

 

</

 

html>

 



Code:

Partial

 

Class RadGrid

 

 

Inherits System.Web.UI.Page

 

 

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

 

 

End Sub

 

End

 

Class

 

0
Casey
Top achievements
Rank 1
answered on 02 Sep 2009, 02:33 PM
Ashwin,

Try placing the below in the code exectued by the NeedDataSource event and put a break point on it. Hovering over the RebindReason part should tell you the reason why the NeedDataSource event is firing.

string reason = e.RebindReason.ToString();     
 

Could you please paste the method that is called during page load that is giving you issues, as well as the value found in RebindReason?

Thanks,
Casey
0
Ashwin Deshpande
Top achievements
Rank 1
answered on 02 Sep 2009, 02:41 PM
On Page Load i am not called any method directly method

Partial

 

Class RadGrid

 

 

Inherits System.Web.UI.Page

 

 

 

 

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

 

 

Dim str As String = e.RebindReason

 

 

End Sub

 

End

 

Class

 



e.RebindReason is Coming as InitialLoad
0
Casey
Top achievements
Rank 1
answered on 02 Sep 2009, 02:54 PM
Have you tried removing the below and/or recreating your RadGrid?

Protected Sub RadGrid1_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource   
 
  Dim str As String = e.RebindReason   
 
End Sub 
 
0
Ashwin Deshpande
Top achievements
Rank 1
answered on 02 Sep 2009, 02:57 PM
Atlast its fixed..

 

If e.RebindReason <> GridRebindReason.InitialLoad Then

 


End if

In the needDataSource event  i applied the above condition and managed to Skip the database Call.......
0
Casey
Top achievements
Rank 1
answered on 02 Sep 2009, 03:10 PM
That is good that you are now able to avoid that initial binding, but it still doesn't answer why the NeedDataSource event was firing when you didn't have the event specified and were not calling it during the PageLoad.

Maybe Telerik will have an idea as to why.

Casey
0
Dennis
Top achievements
Rank 2
answered on 24 Nov 2009, 09:53 PM
Ashwin,

It sounds like you finally have a resolution; however, your original
scenario appeared to be you wanted a user search page to come
up and then the grid (search results) would not be loaded until the
user clicked  a button (search/find).

A simple resolution that I often use is to implement a SQL
statement that evaluates to an empty dataset, object list, etc.
For example if I am searching a table (MyTable) with primary key
(MyId), I might create a SQL statement for a SQLDataSource such
as (Select columns From MyTable Where MyId=-1).  This can be
done declaratively or programmatically in some middle layer.  Since
the SQL is going against the primary key in a single table the
performance is always very good.

Basically, load the grid with an empty dataset (however, you prefer
to create it) when you initially load the page (Not Page.IsPostBack).
If you go with this approach it does not matter when the events fire
(or why they fire).

Just a different perspective.

Regards,
Dennis
0
kavitha
Top achievements
Rank 1
answered on 16 Jun 2011, 03:34 PM
Thanks Ashwin.

e.RebindReason <> GridRebindReason.InitialLoad  helped me
Tags
Grid
Asked by
Ashwin Deshpande
Top achievements
Rank 1
Answers by
Casey
Top achievements
Rank 1
Vlad
Telerik team
Ashwin Deshpande
Top achievements
Rank 1
Dennis
Top achievements
Rank 2
kavitha
Top achievements
Rank 1
Share this question
or