Hi,
I've got a page with one Placeholder on it and nothing else. I've added the RadScriptManager and the RadGrid using the code below and the Paging works ok but the sorting doesn't? No error is thrown. It shows the sorting icons in the column heading but does not actually do the sorting.
If I do exaclty the same using the Designer pages it all works fine. It's trying to do things programmatically that I can't get it to work.
default.aspx
==========
<%@ Page EnableEventValidation="false" Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TelerikGridExample._Default" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<asp:PlaceHolder runat="server" ID="ph"></asp:PlaceHolder>
</body>
</html>
default.aspx.cs
==============
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace TelerikGridExample
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
HtmlForm f1 = new HtmlForm();
// script manager
Telerik.Web.UI.RadScriptManager sm = new Telerik.Web.UI.RadScriptManager();
sm.ID = "RadScriptManager1";
// data source
SqlDataSource ds = new SqlDataSource(@"Data Source=gbe-pc\express2008;Initial Catalog=Northwind;User ID=sa;Password=something", "SELECT categoryid, categoryname FROM [categories]");
ds.ID = "SqlDataSource1";
// rad grid
Telerik.Web.UI.RadGrid rg = new Telerik.Web.UI.RadGrid();
rg.ID = "RadGrid1";
rg.PageSize = 5;
rg.AllowPaging = true;
rg.AllowSorting = true;
rg.AutoGenerateColumns = false;
rg.GroupingEnabled = true;
rg.ClientSettings.AllowDragToGroup = true;
rg.EnableViewState = false;
// add some columns
Telerik.Web.UI.GridBoundColumn c1 = new Telerik.Web.UI.GridBoundColumn();
rg.MasterTableView.Columns.Add(c1);
c1.DataField = "categoryid";
c1.SortExpression = "categoryid";
c1.UniqueName = "categoryid";
c1.DataType = System.Type.GetType("System.Int32");
c1.HeaderText = "categoryid";
Telerik.Web.UI.GridBoundColumn c2 = new Telerik.Web.UI.GridBoundColumn();
rg.MasterTableView.Columns.Add(c2);
c2.DataField = "categoryname";
c2.SortExpression = "categoryname";
c2.UniqueName = "categoryname";
c2.DataType = System.Type.GetType("System.String");
c2.HeaderText = "categoryname";
rg.NeedDataSource += new Telerik.Web.UI.GridNeedDataSourceEventHandler(rg_NeedDataSource);
// add to controls to the ajax panel
f1.Controls.Add(sm);
f1.Controls.Add(ds);
f1.Controls.Add(rg);
ph.Controls.Add(f1);
}
void rg_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
Telerik.Web.UI.RadGrid myrg = (Telerik.Web.UI.RadGrid)Page.FindControl("RadGrid1");
myrg.DataSource = (SqlDataSource)Page.FindControl("SqlDataSource1");
}
}
}