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

RadGrid Paging after bending from search

4 Answers 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lord Vader
Top achievements
Rank 1
Lord Vader asked on 07 Dec 2010, 12:41 PM
Hi,
In this case I am binding the grid programmatically in the page load, then when a user does a search, I am binding the grid with a different dataset, when I enable paging after the search it binds back the original dataset; here is the code:
public partial class PageSearch : System.Web.UI.Page
{
    public ACHPagingDLL.dl dl = new ACHPagingDLL.dl();
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadGrid();
    }
    public void LoadGrid()
    {
        DataSet dsPatients = dl.c_FN_Paging_getAllEmployees();
        rgEmployees.DataSource = dsPatients;
        rgEmployees.DataBind();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (txtSearch.Text.Length < 2)
        {
            litResult.Visible = true;
            litResult.Text = "<FONT color=#cc0000 size=3>Search for 2 or more characters!</FONT>";
            LoadGrid();
            return;
        }
        else
        {
            DataSet dsSearch = dl.c_FN_seachEmployees(txtSearch.Text);
            rgEmployees.DataSource = dsSearch;
            rgEmployees.DataBind();
        }
    }
}
And here is the HTML:
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
        <table class="style4">
            <tr>
                <td class="style5">
                    Search for employee by name:</td>
                <td class="style6">
                    <telerik:RadTextBox ID="txtSearch" Runat="server" Width="160px">
                    </telerik:RadTextBox>
                       
                    <telerik:RadButton ID="btnSearch" runat="server" onclick="btnSearch_Click"
                    Text="Search">
                    </telerik:RadButton>
                </td>
                <td>
                    <asp:Literal ID="litResult" runat="server"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <telerik:RadGrid ID="rgEmployees" runat="server" AllowPaging="True"
                    AutoGenerateColumns="False" GridLines="None" Skin="WebBlue">
                        <MasterTableView pagesize="20">
                            <CommandItemSettings ExportToPdfText="Export to Pdf">
                            </CommandItemSettings>
                            <Columns>
                                <telerik:GridBoundColumn DataField="EmployeeNo" UniqueName="EmployeeNo"
                                Visible="False">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="EmployeeName" HeaderText="Employee"
                                UniqueName="EmployeeName">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Pager" HeaderText="Pager"
                                UniqueName="Pager">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Office" HeaderText="Office#"
                                UniqueName="Office">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Cell" HeaderText="Cell Phone"
                                UniqueName="Cell">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Email" HeaderText="Email"
                                UniqueName="Email">
                                </telerik:GridBoundColumn>
                            </Columns>
                        </MasterTableView>
                        <HeaderContextMenu EnableImageSprites="True"
                        CssClass="GridContextMenu GridContextMenu_Default">
                        </HeaderContextMenu>
                    </telerik:RadGrid>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                     </td>
            </tr>
        </table>
    </telerik:RadAjaxPanel>

I am not sure if there should be a code to be inserted in the index paging?
Please let me know.

Thank you in advance,
Shehab

4 Answers, 1 is accepted

Sort by
0
Lord Vader
Top achievements
Rank 1
answered on 07 Dec 2010, 12:44 PM
UPDATE:
I added an is not post back in the page load, now after the search, when I try to navigate pages, it goes blank...
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            LoadGrid();
        }
    }
0
Iana Tsolova
Telerik team
answered on 08 Dec 2010, 12:54 PM
Hello Shehabeldin,

The described behavior is rather expected with the simple data-binding you are using for the grid. I suggest that you bind the grid through its NeedDataSource event. There you only should assing the RadGrid DataSource property and remove any other assingments to this property from the page code as well as the DataBind() method calls.

For more information, please refer to the below articles:

http://www.telerik.com/help/aspnet-ajax/grdsimpledatabinding.html
http://www.telerik.com/help/aspnet-ajax/grdadvanceddatabinding.html

Regards,
Iana
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Lord Vader
Top achievements
Rank 1
answered on 08 Dec 2010, 01:06 PM
Thank you for your reply.
If I bind the grid in need data source, how am I going to bind the grid when users search for patient name's as I showed in the code?
0
Iana Tsolova
Telerik team
answered on 08 Dec 2010, 02:21 PM
Hi Shehabeldin,

In the button click event you can call the Rebind() method for the grid. This will invoke the NeedDataSource event so you can move the logic for getting/filtering the data there.

Greetings,
Iana
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Lord Vader
Top achievements
Rank 1
Answers by
Lord Vader
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or