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
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
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.
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
OnNeedDataSource
="NeedDataSource"
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>
Casey
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
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
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
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 |
If e.RebindReason <> GridRebindReason.InitialLoad Then
End if
In the needDataSource event i applied the above condition and managed to Skip the database Call.......
Maybe Telerik will have an idea as to why.
Casey
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
e.RebindReason <> GridRebindReason.InitialLoad helped me