i have textbox with search button to filter radgrid ,I get the filtered data without problem but when I click on next page in the grid
the grid postback , so the filtered data is missed ,so I get the whole data again
could you help me who can I solve this issue
thanks in advance
ghadeer
8 Answers, 1 is accepted
<table class="style1">
<
tr>
<td colspan="2">
<table class="style1">
<tr>
<
td class="style2">
<asp:Label ID="Label1" runat="server"Text="Search Option:"></asp:Label> </td>
<td align="left">
<
asp:RadioButtonList ID="rblSearchs" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Selected="True" Value="0">Referal ID</asp:ListItem>
<asp:ListItem Value="1">Hospital ID</asp:ListItem>
<asp:ListItem Value="2">Area ID</asp:ListItem>
</asp:RadioButtonList>
</td> </tr>
<tr> <td class="style2">
<asp:Label ID="Label2" runat="server" Text="Search Text:"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtSearch" runat="server" Width="262px"></asp:TextBox>
<
asp:Button ID="btnSearch" runat="server" Text="Find" CssClass="btn" onclick="btnSearch_Click"/>
<asp:Button ID="btnSearchAll" runat="server" Text="Show All" />
</td> </tr>
</
table>
<
/td> </tr>
<tr>
<td colspan="2">
<
telerik:RadGrid ID="rGridReferalDetails" runat="server" AllowPaging="True" AutoGenerateColumns="False" GridLines="None" onneeddatasource="rGridReferalDetails_NeedDataSource" Skin="Office2007"
onprerender="rGridReferalDetails_PreRender" >
<ClientSettings>
<Selecting AllowRowSelect="True" />
<Selecting AllowRowSelect="True"/>
</ClientSettings>
<MasterTableView>
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn Resizable="False" Visible="False">
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="RID" HeaderText="Referal ID" UniqueName="RID" >
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="hospital_name" HeaderText="Hospital Name" UniqueName="hospital_name" AllowFiltering="False">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="area_name" HeaderText="Area Name" UniqueName="area_name"AllowFiltering="False"> </telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="note" HeaderText="Transaction"
UniqueName="note" AllowFiltering="False"> </telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Rejectreason_name"
HeaderText="Rejectreason_name" UniqueName="Reject Reason" AllowFiltering="False"> </telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Createdby" HeaderText="User"UniqueName="Createdby" AllowFiltering
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="createddate" HeaderText="Date"
UniqueName="createddate" AllowFiltering="False"> </telerik:GridBoundColumn>
<
/Columns>
<EditFormSettings>
<PopUpSettings ScrollBars="None" />
<PopUpSettings ScrollBars="None" />
</EditFormSettings>
</MasterTableView>
<
/telerik:RadGrid></td> </tr> <tr><td align="left">
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<
AjaxSettings>
<telerik:AjaxSetting AjaxControlID="btnSearch">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="rGridReferalDetails"/>
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
</td>
<td align="left">
<asp:HiddenField ID="hdDisplayMode" runat="server"/>
</td>
</tr>
</table>
Sorry I didnt get you.
this is the code behind page:
protected void Page_Load(object sender, EventArgs e)
{
_controller =
new Controller.Referal(this);
if (!IsPostBack)
{
try
{
DisplayMode =
"ALL";
_controller.GetReferal();
}
catch (Exception)
{
}
 
finally
{
}
}
}
#region
button click event
protected void btnSearch_Click(object sender, EventArgs e)
{
try
{
DisplayMode =
"Search";
rGridReferalDetails.CurrentPageIndex = 0;
_controller.GetReferal();
}
catch
{
}
}
#endregion
protected
void rGridReferalDetails_PageIndexChanged(object source, GridPageChangedEventArgs e)
{
}
I see when I click next page in the grid postback takeplace!!!!
thanks in advance
_controller =
new
Controller.Referal(
this
);
You are getting a new instance of the controller every time you load the page and on the secoond postback (pageindexchanged) your dataset is changing. Your are not passing the correct parameters to your data access class. If you can post a sample project that would be better.
Hi ,
thank you....
controller is my business class also this :
_controller =
new Controller.Referal(this);
is already defined in the page load, regarding needdatasource event I had used it before but I changed
during my attemp to solve the problem,
I will copy the page again:
public
partial class ReferalDetails : System.Web.UI.Page, IReferal
{
#region
fields
private Controller.Referal _controller = null;
#endregion
protected void Page_Load(object sender, EventArgs e)
{
_controller =
new Controller.Referal(this);
if (!IsPostBack)
{
try
{
DisplayMode =
"ALL";
_controller.GetReferal();
}
catch (Exception)
{
}
 
finally
{
}
}
}
 
#region
interface IReferal implementation
public int Filter
{
get { return Convert.ToInt32(rblSearchs.SelectedItem.Value); }
}
public int FilterText
{
get { return Convert.ToInt32(txtSearch.Text); }
}
 
 
public void Clear()
{
txtSearch.Text =
string.Empty;
}
public String DisplayMode
{
get
{
return Session[" DisplayMode"].ToString();
}
 
set { Session[" DisplayMode"] = value.ToString(); }
}
 
public void MessageAlert(string Text)
{
ScriptManager.RegisterStartupScript(Page, typeof(Page), "RegisterScript", "window.alert('" + Text + "')", true);
}
 
public IListSource ReferalList
{
set
{
rGridReferalDetails.DataSource =
value;
rGridReferalDetails.DataBind();
}
}
#endregion
#region
button click event
protected void btnSearch_Click(object sender, EventArgs e)
{
try
{
DisplayMode =
"Search";
rGridReferalDetails.CurrentPageIndex = 0;
_controller.GetReferal();
}
catch
{
}
}
#endregion
 
protected void btnSearchAll_Click(object sender, EventArgs e)
{
try
{
Clear();
DisplayMode =
"ALL";
rGridReferalDetails.CurrentPageIndex = 0;
_controller.GetReferal();
}
catch
{
}
}
 
 
protected void rGridReferalDetails_PageIndexChanged(object source, GridPageChangedEventArgs e)
{
}
}
I think you get exactly what is my problem,every time I click on next page,,page postback and filtered data is lost.
thanks in advance
I would check the following demo to ensure you have what you need.
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/needdatasource/defaultcs.aspx