How to search for data from a Telerik RadGrid?

advertisements

I'am new in C# and Telerik.

I have a radgrid with a MasterTableView with some columns. I am using stored procedures to insert, update and delete data.

What I want is to search RadGrid data through my table. How can I do this?

<h6>Filtros</h6>
<table class="table table-condensed" style="margin-top: 25px; padding-top: 10px;">
    <tr>
        <td style="width: 80px">Filtro
        </td>
        <td style="width: 30%;">
            <telerik:RadTextBox ID="txtFiltro" runat="server" EmptyMessage="insert name, department or teacher group" Width="90%"></telerik:RadTextBox>
        </td>
        <td>
            <telerik:RadButton ID="lbSearch"
                Visible="true"
                runat="server"
                Text="pesquisar"
                CausesValidation="false"
                Style="background-color: #FFFFFF">
                <Icon PrimaryIconCssClass="icon-search" PrimaryIconLeft="5px" PrimaryIconTop="4px" />
            </telerik:RadButton>
        </td>
    </tr>
</table>   

<telerik:RadGrid ID="lstProfessores" runat="server"  AutoGenerateColumns="False" CellSpacing="0"GridLines="None"OnInsertCommand="lstProfessores_InsertCommand"OnUpdateCommand="lstDocentes_UpdateCommand" >

    <MasterTableView  CommandItemDisplay="Top">
        <Columns>
            <telerik:GridButtonColumn ButtonCssClass="icon-pencil" UniqueName="Edit" CommandName="Edit">
                <HeaderStyle Width="30px" />
            </telerik:GridButtonColumn>       

            <telerik:GridButtonColumn ButtonCssClass="icon-trash" UniqueName="Delete" CommandName="Delete" ConfirmDialogType="RadWindow" ConfirmText="Continuar com a remoção?">
                <HeaderStyle Width="30px" />
            </telerik:GridButtonColumn>       

            <telerik:GridBoundColumn HeaderText="IdTeacher" DataField="IdTeacher" UniqueName="IdTeacher" DataType="System.Int32" SortExpression="IdTeacher">
                    <ColumnValidationSettings>
                    <ModelErrorMessage Text=""></ModelErrorMessage>
                    </ColumnValidationSettings>
            </telerik:GridBoundColumn>

            <telerik:GridBoundColumn HeaderText="Name" DataField="Name" UniqueName="Name" SortExpression="Name">
                    <ColumnValidationSettings>
                    <ModelErrorMessage Text=""></ModelErrorMessage>
                    </ColumnValidationSettings>
            </telerik:GridBoundColumn>

            <telerik:GridBoundColumn DataField="Department" HeaderText="Departamento" SortExpression="Departamento" UniqueName="Departamento">
                    <ColumnValidationSettings>
                        <ModelErrorMessage Text="" />
                    </ColumnValidationSettings>
            </telerik:GridBoundColumn>

            <telerik:GridBoundColumn DataField="TeacherGroup" HeaderText="TeacherGroup" SortExpression="TeacherGroup" UniqueName="TeacherGroup">
                    <ColumnValidationSettings>
                        <ModelErrorMessage Text="" />
                    </ColumnValidationSettings>
            </telerik:GridBoundColumn>
            <telerik:GridEditCommandColumn />
        </Columns>

    </MasterTableView>
</telerik:RadGrid>


How are you populating the grid, through a view/table model? If so, then you just need to tap into the data binding event and filter your results.

protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    var dataSource = myDataSource.Where(s => s.ColumnToSearch == mySearchTextBoxValue);
    RadGrid1.DataSource = dataSource;
}

If you are populating the grid with a stored procedure, then it will be more difficult.