Panelbar and Grid Issue

3 posts, 0 answers
  1. Sahar
    Sahar avatar
    5 posts
    Member since:
    Sep 2013

    Posted 07 Oct 2013 Link to this post

    Hi,
    i wanna when click on the item in radpanelbar to load grid according to this item but if i use paging or any thing in the grid require to click on this item again .
    how can i solve this issue plz

    Thanks!
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Oct 2013 Link to this post

    Hi Sahar,

    In order to operate advanced features like Paging in RadGrid the better approach is to use NeedDataSource as follows.

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" AutoGenerateColumns="true"
        PageSize="4" OnNeedDataSource="RadGrid1_NeedDataSource" OnPageIndexChanged="RadGrid1_PageIndexChanged">
    </telerik:RadGrid>
    <telerik:RadPanelBar ID="RadPanelBar1" runat="server" DataFieldID="CategoryID" DataSourceID="SqlDataSource1"
        DataTextField="CategoryID" OnItemClick="RadPanelBar1_ItemClick">
    </telerik:RadPanelBar>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT top 10 [CategoryID], [CategoryName], [Description] FROM [Categories]">
    </asp:SqlDataSource>

    C#:
    protected void RadPanelBar1_ItemClick(object sender, Telerik.Web.UI.RadPanelBarEventArgs e)
    {
        String connectionstring = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
        SqlConnection sqlconn = new SqlConnection(connectionstring);
        sqlconn.Open();
        DataTable dt = new DataTable();
        string selectQuery="select * from Products where CategoryID ="+RadPanelBar1.SelectedItem.Text+"";
        SqlDataAdapter dr = new SqlDataAdapter(selectQuery, sqlconn);
        sqlconn.Close();
        dr.Fill(dt);
        ViewState["dt"] = dt;
        RadGrid1.DataSource = dt;
        RadGrid1.DataBind();
    }
    protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        DataTable dt = (DataTable)ViewState["dt"];
        RadGrid1.DataSource = dt;
     
    }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sahar
    Sahar avatar
    5 posts
    Member since:
    Sep 2013

    Posted 08 Oct 2013 Link to this post

    it works well .... thanks Princy
Back to Top