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

Sorting and Paging not work in RadGridView

1 Answer 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
rahul
Top achievements
Rank 1
rahul asked on 11 Nov 2010, 10:47 AM
Hi,
     I'm create a HelpDesk project.In this i'm show all the ticket's according to status(Pending/Resolved).In one column im show ticket subject and Ticket Detail.when i'm click on any column for sorting then my gridview not show any data.but again when click on button then that is show the sorted data.It's also happens in paging.

       so please any one tell the way that i'm able to sort the ticket and also paging is work.I'm attached code please find...


using

 

System;

 

using

 

System.Collections;

 

using

 

System.Collections.Generic;

 

using

 

System.Linq;

 

using

 

System.Web;

 

using

 

System.Web.UI;

 

using

 

System.Web.UI.WebControls;

 

using

 

DotNetNuke.Entities.Modules;

 

using

 

DotNetNuke.Entities.Modules.Definitions;

 

using

 

DotNetNuke.Entities.Users;

 

using

 

DotNetNuke.Security.Permissions;

 

using

 

Mandeeps.HelpDesk.Base.Library.Data;

 

using

 

Telerik.Web.UI;

 

namespace

 

Mandeeps.DNN.Modules.HelpDesk

 

{

 

public partial class DnnHelpDesk : PortalModuleBase

 

{

Mandeeps.HelpDesk.Base.Library.

HelpDesk lhd;

 

 

ModuleSecurity ms;

 

 

protected void Page_Load(object sender, EventArgs e)

 

{

ms =

new ModuleSecurity(this.ModuleConfiguration);

 

InitModulePermissions();

 

Mandeeps.DNN.Modules.HelpDesk.Data.

HelpdeskSettingDataContext context = new Modules.HelpDesk.Data.HelpdeskSettingDataContext(DotNetNuke.Common.Utilities.Config.GetConnectionString());

 

 

 

foreach (Mandeeps.DNN.Modules.HelpDesk.Data.HelpdeskSetting h in context.HelpdeskSettings)

 

{

lhd =

new Mandeeps.HelpDesk.Base.Library.HelpDesk(DotNetNuke.Common.Utilities.Config.GetConnectionString());

 

lhd.Pop3 =

new Mandeeps.HelpDesk.Base.Library.Mail.Pop3(h.Pop3LicenseKey, h.Pop3Server, h.Pop3Username, h.Pop3Password);

 

lhd.Smtp =

new Mandeeps.HelpDesk.Base.Library.Mail.Smtp(h.SmtpLicenseKey, h.SmtpServer, h.SmtpUsername, h.SmtpPassword);

 

lhd.Smtp.ServerPort = 2525;

lhd.PortalId = PortalId;

}

 

if(!IsPostBack)

 

Initilize();

}

 

public void Initilize()

 

{

 

List<Ticket> tic=null;

 

 

if(ms.IsOperator)

 

{

rtbSetting.Visible =

false;

 

rtbView.Items[0].Text =

"UnAssigned Tickets";

 

rtbView.Items[0].ToolTip =

"Click here for show UnAssigned Ticket's";

 

rtbView.Items[2].Text =

"My Tickets";

 

rtbView.Items[2].ToolTip =

"Click here for show Self Assigned Ticket's";

 

rtbView.Items[3].Visible =

true;

 

rtbView.Items[4].Visible =

true;

 

rgTicket.Columns[3].Visible =

true;

 

tic = lhd.GetAllOpenTickets(

null, UserId);

 

 

if (tic.Count == 0)

 

{

tic = lhd.GetAllUnassignedTickets();

((rtbView.Items[0])

as RadToolBarButton).Checked = true;

 

}

 

else

 

((rtbView.Items[2])

as RadToolBarButton).Checked = true;

 

}

 

else

 

tic = lhd.GetAllOpenTickets(UserId);

 

rgTicket.DataSource = tic;

rgTicket.DataBind();

}

 

protected void rtbSetting_ButtonClick(object sender, RadToolBarEventArgs e)

 

{

 

if (e.Item.Text == "Add New Ticket")

 

Response.Redirect(EditUrl(

"AddNewTicket"));

 

}

 

protected void rtbView_ButtonClick(object sender, RadToolBarEventArgs e)

 

{

 

List<Ticket> ticket = new List<Ticket>();

 

 

switch (e.Item.Text)

 

{

 

case "Pending":

 

{

rgTicket.Columns[6].Visible =

false;

 

ticket = lhd.GetAllOpenTickets(UserId);

 

break;

 

}

 

case "Resolved":

 

{

rgTicket.Columns[6].Visible =

true;

 

ticket = lhd.GetAllCloseTickets(UserId);

 

break;

 

}

 

case "UnAssigned Tickets":

 

{

rgTicket.Columns[4].Visible =

false;

 

rgTicket.Columns[6].Visible =

false;

 

ticket = lhd.GetAllUnassignedTickets();

 

break;

 

}

 

case "My Tickets":

 

{

rgTicket.Columns[4].Visible =

false;

 

rgTicket.Columns[6].Visible =

false;

 

ticket = lhd.GetAllOpenTickets(

null,UserId);

 

 

break;

 

}

 

case "All Tickets":

 

{

rgTicket.Columns[4].Visible =

true;

 

rgTicket.Columns[6].Visible =

false;

 

ticket = lhd.GetAllOpenTickets();

 

break;

 

}

}

 

rgTicket.DataSource = ticket;

rgTicket.DataBind();

}

 

protected void rgTicket_ItemDataBound(object sender, GridItemEventArgs e)

 

{

 

if (e.Item is GridDataItem)

 

{

 

GridDataItem item = e.Item as GridDataItem;

 

 

TableCell title = item["Title"];

 

 

if (title != null)

 

{

 

Control ctl = title.FindControl("hlTicketDetails");

 

 

if (ctl != null)

 

{

 

HyperLink ticketDetails = ctl as HyperLink;

 

 

Label ticketId = title.FindControl("lTicketDetails") as Label;

 

Mandeeps.HelpDesk.Base.Library.Data.

Ticket t = item.DataItem as Mandeeps.HelpDesk.Base.Library.Data.Ticket;

 

ticketId.Text =

"#" + t.TicketID.ToString();

 

 

if (t.Title.Length > 25)

 

ticketDetails.Text = t.Title.Substring(0, 25)+

"...";

 

 

else

 

ticketDetails.Text = t.Title;

ticketDetails.NavigateUrl = EditUrl(

"", "", "ViewTicketDetail", "TicketID=" + t.TicketID.ToString());

 

}

}

}

}

 

public string ConcatColumns(object objText)

 

{

 

if (objText.ToString().Length > 50)

 

 

return objText.ToString().Substring(0, 50)+ "...";

 

 

 

else

 

 

return objText.ToString();

 

}

 

public string CategoryName(object objText)

 

{

 

if (int.Parse(objText.ToString()) == 0)

 

 

return "";

 

 

else

 

 

return lhd.GetCategoryName(int.Parse(objText.ToString()));

 

}

 

public string AssignedToName(object objText)

 

{

 

if (int.Parse(objText.ToString()) == -1)

 

 

return "";

 

 

else

 

{

 

UserController uC = new UserController();

 

 

UserInfo user = uC.GetUser(PortalId, int.Parse(objText.ToString()));

 

 

return user.DisplayName;

 

}

}

 

}

 

protected void rgTicket_SortCommand(object sender, GridSortCommandEventArgs e)

 

{

}

}

}















<%

@ Control Language="C#" AutoEventWireup="true" CodeBehind="DnnHelpDesk.ascx.cs" Inherits="Mandeeps.DNN.Modules.HelpDesk.DnnHelpDesk" %>

 

<%

@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

 

 

<

 

telerik:RadToolBar ID="rtbSetting" runat="server" onbuttonclick="rtbSetting_ButtonClick" style="float:left">

 

 

<Items>

 

 

<telerik:RadToolBarButton runat="server" Text="Add New Ticket" ToolTip="Click here for Add New Ticket"/>

 

 

</Items>

 

</

 

telerik:RadToolBar>

 

<

 

telerik:RadToolBar ID="rtbView" runat="server" onbuttonclick="rtbView_ButtonClick" EnableShadows="True" style="float:right">

 

 

<Items>

 

 

<telerik:RadToolBarButton runat="server" Text="Pending" ToolTip="Click here for show Pending Ticket's" CheckOnClick="true" AllowSelfUnCheck="true" />

 

 

<telerik:RadToolBarButton runat="server" Text="Button 2" IsSeparator="True"/>

 

 

<telerik:RadToolBarButton runat="server" Text="Resolved" ToolTip="Click here for show Resolved Ticket's" CheckOnClick="true" AllowSelfUnCheck="true"/>

 

 

<telerik:RadToolBarButton runat="server" Text="Button 3" IsSeparator="True" Visible="false"/>

 

 

<telerik:RadToolBarButton runat="server" Text="All Tickets" ToolTip="Click here for show All Ticket's" Visible="false" CheckOnClick="true" AllowSelfUnCheck="true"/>

 

 

</Items>

 

</

 

telerik:RadToolBar><br style="clear:both;"/>

 

 

<

 

telerik:RadGrid ID="rgTicket" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" GridLines="None"

 

 

PageSize="4" onitemdatabound="rgTicket_ItemDataBound" Skin="Outlook" onsortcommand="rgTicket_SortCommand">

 

 

 

<MasterTableView>

 

 

<CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>

 

 

<RowIndicatorColumn>

 

 

<HeaderStyle Width="20px"/>

 

 

</RowIndicatorColumn>

 

 

<ExpandCollapseColumn>

 

 

<HeaderStyle Width="20px"/>

 

 

</ExpandCollapseColumn>

 

 

<Columns>

 

 

<telerik:GridBoundColumn DataField="TicketID" HeaderText="TicketID" SortExpression="TicketID" UniqueName="TicketID" Visible="False"/>

 

 

 

<telerik:GridTemplateColumn HeaderText="Ticket Detail" UniqueName="Title">

 

 

<ItemTemplate>

 

 

<asp:HyperLink ID="hlTicketDetails" runat="server" Text="Subject Appears Here" Font-Size="Small" ForeColor="#0000ff"/>

 

 

<asp:Label ID="lTicketDetails" runat="server" Font-Size="Smaller" style="float:right"/><br/>

 

 

<div>

 

 

<asp:Label id="Label1" runat="server" Text='<%#ConcatColumns(DataBinder.Eval(Container.DataItem,"Description")) %>' ForeColor="#6699ff"/></div>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridTemplateColumn HeaderText="Category" UniqueName="Title">

 

 

<ItemTemplate>

 

 

<asp:Label id="lcategory" runat="server" Text='<%#CategoryName(DataBinder.Eval(Container.DataItem,"CategoryId")) %>'/>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridBoundColumn DataField="Email" HeaderText="From" SortExpression="Email" UniqueName="Email" Visible="false"/>

 

 

<telerik:GridTemplateColumn HeaderText="Assigned To" UniqueName="Title" Visible="false">

 

 

<ItemTemplate>

 

 

<asp:Label id="lAssignedTo" runat="server" Text='<%#AssignedToName(DataBinder.Eval(Container.DataItem,"AssignedTo")) %>'/>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridBoundColumn DataField="OpenDateTime" HeaderText="Created On" SortExpression="OpenDateTime" UniqueName="OpenDateTime"/>

 

 

<telerik:GridBoundColumn DataField="CloseDateTime" HeaderText="Date Close" SortExpression="CloseDateTime" UniqueName="CloseDateTime" Visible="false"/>

 

 

</Columns>

 

 

</MasterTableView>

 

</

 

telerik:RadGrid>

 

1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 11 Nov 2010, 11:06 AM
Hi Rahul,

From your code snippet I saw that you are using the Simple DataBinding. However simple data-binding can be used in simple cases when you do not require the grid to perform complex operations such as
  • Inserting, deleting, and updating records through custom edit forms (WebUserControl or FormTemplate)
  • Grouping
  • Hierarchy relations
  • Filtering
  • Sorting
  • Paging
For advanced features such as those listed above, RadGrid must be bound using declarative data sources or through the NeedDataSource event. Could you please try using the advanced data binding with NeedDataSource event and move the logic for populating the RadGrid with data from Page_Load to NeedDataSource event and let me know if the issue  still persists.
Also please check out the following online documentation articles which explain how to perform sorting and filtering over GridTemplateColumn:
http://www.telerik.com/help/aspnet-ajax/grdimplementingfilteringfortemplatecolumns.html
http://www.telerik.com/help/aspnet-ajax/grdsortingforhyperlinktemplatecolumns.html

Sincerely yours,
Radoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
rahul
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or