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

Sorting with the dataset

3 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Saran kumar
Top achievements
Rank 1
Saran kumar asked on 06 Jan 2010, 05:56 AM
hi
im having a grid as shown in the attachement. i need to sort the grid with the dataset in binding into the grid. im calling an sp for the dataset.
the code is :
objBizReport = new BizReport();  
 
                DataSet dsReport = objBizReport.GetDeletedLeads(orgId, fromDate, toDate);  
 
gvReport_Leads.DataSource = dsReport.Tables[2];  
                        gvReport_Leads.DataBind(); 

i dont have any parameter called ASC/DESC to pass each time on sort command. pleas help me on this.

<telerik:RadGrid ID="gvReport_Leads" runat="server" CssClass="radgrid" AllowPaging="True" 
                EnableEmbeddedSkins="false" ShowFooter="false" AutoGenerateColumns="False" GridLines="None" 
                AllowSorting="True" Width="800 px" AllowMultiRowSelection="true" OnItemDataBound="gvReport_Leads_ItemDataBound" 
                OnSortCommand="gvReport_Leads_SortCommand">  
                <MasterTableView CssClass="radgridMasterTable" AllowCustomSorting="true" Width="100%" 
                    ShowHeadersWhenNoRecords="true" TableLayout="Fixed" ClientDataKeyNames="lead_id"

i used gridbound columns with above grid declaration and mastertable view.

the sorting command:
protected void gvReport_Leads_SortCommand(object source, GridSortCommandEventArgs e)  
        {  
              
                GridSortExpression sortExpr = new GridSortExpression();  
                switch (e.OldSortOrder)  
                {  
                    case GridSortOrder.None:  
                        sortExpr.FieldName = e.SortExpression;  
                        sortExpr.SortOrder = GridSortOrder.Descending;  
 
                        e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);  
                        break;  
                    case GridSortOrder.Ascending:  
                        sortExpr.FieldName = e.SortExpression;  
                        sortExpr.SortOrder = gvReport_Leads.MasterTableView.AllowNaturalSort ? GridSortOrder.None : GridSortOrder.Descending;  
                        e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);  
                        break;  
                    case GridSortOrder.Descending:  
                        sortExpr.FieldName = e.SortExpression;  
                        sortExpr.SortOrder = GridSortOrder.Ascending;  
 
                        e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);  
                        break;  
                }  
 
                e.Canceled = true;  
                gvReport_Leads.Rebind(); 
sort command tries sorting but its not refelcting any change in order in the grid, i cannot implement onneedsource since im using SP or dataset. please help, i think if i have onneeddatasource for the above senario, it will work. help me in coding onneeddata source for this.

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 06 Jan 2010, 09:42 AM
Hi Saran,

The advantage of using the NeedDataSource event is that you have the flexibility of generating your data source in the code-behind, but are freed from handling the logic of when and how data-binding should take place.
Please, check out this articles, which elaborates on how to use NeedDataSource event:
http://www.telerik.com/help/aspnet-ajax/grid-advanced-data-binding.html
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/needdatasource/defaultcs.aspx

Regards,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Saran kumar
Top achievements
Rank 1
answered on 06 Jan 2010, 10:16 AM
on the link u sent they have just used SQL query for retriving records.
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
        {  
            RadGrid1.DataSource = GetDataTable("SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, PostalCode FROM Customers");  
        }  
    }  
 
but in my case i used
protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)  
        {  
                        int orgId;  
            string fromDate = Request.QueryString["fromdate"].ToString();  
            string toDate = Request.QueryString["todate"].ToString();  
            orgId = UserSession.OrgId;  
            objBizReport = new BizReport();  
 
            DataSet dsReport = objBizReport.GetDeletedLeads(orgId, fromDate, toDate);  
            gvReport_Leads.DataSource = dsReport.Tables[2];  
            //gvReport_Leads.Rebind();  
        }  
 
but i cant make it its throwing an exception
0
Pavlina
Telerik team
answered on 06 Jan 2010, 04:42 PM
Hello Saran,

Attached to this message is as simple working project which handles the desired functionality. Please, give it a try and let me know if you need additional assistance.

I hope this helps.

Best wishes,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Saran kumar
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Saran kumar
Top achievements
Rank 1
Share this question
or