Hi everyone,
I want to filter grid with by textbox. This textbox has got property autocomplete. I want to run this code in textbox onchange method. I write this code but I always need press for filter the grid. How can I fix this
Best Regards
I want to filter grid with by textbox. This textbox has got property autocomplete. I want to run this code in textbox onchange method. I write this code but I always need press for filter the grid. How can I fix this
<
telerik:RadScriptManager
ID
=
"ScriptManager1"
runat
=
"server"
EnableScriptGlobalization
=
"True"
EnableTheming
=
"True"
>
</
telerik:RadScriptManager
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"False"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
AllowPaging
=
"true"
AllowFilteringByColumn
=
"true"
EnableLinqExpressions
=
"false"
>
<
MasterTableView
CommandItemDisplay
=
"Top"
DataKeyNames
=
"ID"
EditMode
=
"InPlace"
>
<
CommandItemSettings
ShowExportToPdfButton
=
"true"
/>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"ID"
UniqueName
=
"ID"
HeaderText
=
"ID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"Name"
DataField
=
"Name"
>
<
FilterTemplate
>
<
asp:TextBox
ID
=
"TextBox1"
runat
=
"server"
AutoPostBack
=
"True"
OnTextChanged
=
"TextBox1_TextChanged"
></
asp:TextBox
>
</
FilterTemplate
>
<
ItemTemplate
>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
Text='<%# Eval("Name") %>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridEditCommandColumn
>
</
telerik:GridEditCommandColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
dynamic data = new[] {
new { ID = 1, Name ="aaa"},
new { ID = 2, Name = "bbb"},
new { ID = 3, Name = "ccc"},
new { ID = 4, Name = "ddd"},
new { ID = 5, Name ="eee"}
};
RadGrid1.DataSource = data;
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
TextBox TextBox1 = sender as TextBox;
RadGrid1.MasterTableView.FilterExpression = "([Name] LIKE \'%" + TextBox1.Text.Trim() + "%\') ";
GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("Name");
column.CurrentFilterFunction = GridKnownFunction.Contains;
column.CurrentFilterValue = TextBox1.Text.Trim();
RadGrid1.Rebind();
}
Best Regards