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

Panelbar and Grid Issue

2 Answers 20 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Sahar
Top achievements
Rank 1
Sahar asked on 07 Oct 2013, 05:27 PM
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 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 08 Oct 2013, 05:52 AM
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.
0
Sahar
Top achievements
Rank 1
answered on 08 Oct 2013, 12:50 PM
it works well .... thanks Princy
Tags
PanelBar
Asked by
Sahar
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Sahar
Top achievements
Rank 1
Share this question
or