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

Filter grid from Combo Box

1 Answer 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simon Channell
Top achievements
Rank 1
Simon Channell asked on 15 May 2017, 02:00 PM

I am using this example

 

http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/how-to/Filtering/radgrid-filtered-by-radcombobox

I want to choose the data for the grid by selecting an item in a drop down list.

I want to initialise the grid from the code behind.

How do I do this? My grid is not refreshing at the moment.

This is the code for my aspx page

 

<div class="panel panel-primary">
<div class="panel-heading">
Your Notes
</div>
</div>
<telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanelN"></telerik:RadAjaxLoadingPanel>
<telerik:RadDropDownList runat="server" ID="RadDropDownStudents" DefaultMessage="Select a student" DropDownWidth="300px" Width="350px"
DataValueField="student_id" DataTextField="Studentname" OnItemSelected="RadDropDownStudents_ItemSelected"
OnSelectedIndexChanged="RadDropDownStudents_SelectedIndexChanged" AutoPostBack="true">
</telerik:RadDropDownList>
<telerik:RadGrid runat="server" ID="RadGridNotes" ShowFooter="false" Width="100%" enableajax="true" ShowStatusBar="true" OnItemCommand="Grid_RowSelect"
allowaddingrecords="false" AutoGenerateColumns="false" AllowSorting="false" allowpagesizeselection="False" OnItemDataBound="OnItemDataBoundHandler" Autobind="false"
AllowPaging="True" Skin="Bootstrap" PageSize="5" OnNeedDataSource="RadGridNotes_NeedDataSource" OnPreRender="RadGridNotes_PreRender" CssClass="table table-striped">
<MasterTableView AutoGenerateColumns="false" DataKeyNames="note_ref" TableLayout="Auto" EditMode="EditForms">
<Columns>
<telerik:GridButtonColumn CommandName="View" HeaderStyle-BackColor="#428bca" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" Text="View" UniqueName="View">
</telerik:GridButtonColumn>
<telerik:GridBoundColumn DataField="note_ref" DataType="System.Int32" HeaderText="note_ref" HeaderStyle-BackColor="#428bca" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" UniqueName="note_ref" Display="false" runat="server" ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="course" HeaderText="code" HeaderStyle-BackColor="#428bca" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" UniqueName="course" Display="false" runat="server" ItemStyle-Width="10px" HeaderStyle-Width="10px">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="courseName" HeaderText="Subject" HeaderStyle-BackColor="#428bca" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" UniqueName="qualname" HeaderStyle-Width="200px" ItemStyle-Width="200px" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="NewNoteType" HeaderText="Type" HeaderStyle-BackColor="#428bca" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" UniqueName="noteType" Display="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="typeDesc" HeaderText="Note Type" HeaderStyle-BackColor="#428bca" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" UniqueName="typeDesc" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="true">
</telerik:GridBoundColumn>
<telerik:GridDateTimeColumn DataField="created" HeaderText="Created" HeaderStyle-BackColor="#428bca" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" UniqueName="created" DataFormatString="{0:dd/MM/yyyy}">
</telerik:GridDateTimeColumn>
<telerik:GridBoundColumn DataField="created_by" HeaderText="Created" HeaderStyle-BackColor="#428bca" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" UniqueName="created_by" Display="false" ItemStyle-HorizontalAlign="Left">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="note_content" HeaderText="Created" HeaderStyle-BackColor="#428bca" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" UniqueName="note_content" Display="false" ItemStyle-HorizontalAlign="Center">
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings EditFormType="Template">
<EditColumn UniqueName="View">
</EditColumn>
<FormTemplate>
<table style="width: 100%" border="0">
<tr>
<td><b>Details</b><br /><br />
<asp:Label ID="LabelDetails" runat="server" Text='<%# Bind("note_content") %>'></asp:Label>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
<PagerStyle Mode="NextPrev" Position="Bottom" PageSizeControlType="RadComboBox"></PagerStyle>
</MasterTableView>
<ClientSettings EnablePostBackOnRowClick="True">
<Selecting AllowRowSelect="True" />
<ClientEvents OnRowDblClick="RowDblClick" OnRowSelected="RowSelected" />
</ClientSettings>

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Marin Bratanov
Telerik team
answered on 18 May 2017, 08:26 AM

Hello Simon,

You can use the NeedDataSource event of the grid to provide it with data according to your own data source. This query can use the SelectedItem or SelectedValue of the dropdown.

In the SelectedIndexChanged of the dropdown, you can simply call the .Rebind() method of the grid.

Regards,

Marin Bratanov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Simon Channell
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or