I had one rad combo and rad grid in my web page. based on the rad combo value, i have to retrive the data from database and load it to the RadGrid. So i enabled selectedIndexChangeEvent for radcombo. In this just i called radgrid.Rebind(). I have raised OnNeedDatasource event for Rad grid. In this i am getting the radcombo value and pass it the one method, it will return datatable. I assigned this datatable into the RadGrid datasource. Paging, filtering is working fine but sort is not working. If i call rebind in the page_load event, then sort and Paging is working but Filter is not working. I have to call radgrid.Rebind() while sort action is performed. How do i correct this problem?
Sample Code:
protected
void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
rCboProject.DataSource = GetProjects();
rCboProject.DataTextField =
"Project";
rCboProject.DataValueField =
"Project";
rCboProject.DataBind();
rgDetails.Rebind();
}
else
{
//rgDetails.Rebind();
}
}
///
<summary>
/// Get the Projects
/// </summary>
/// <returns>Return the Project list in datatable</returns>
private DataTable GetProjects()
{
try
{
DataSet dsProjectDetails = new DataSet();
// TODO to get the Project details from database
if (dsProjectDetails == null || dsProjectDetails.Tables.Count == 0)
return null;
if (dsProjectDetails.Tables["ProjectDetails"].Rows.Count > 1)
{
DataRow newRow = dsProjectDetails.Tables["ProjectDetails"].NewRow();
newRow[
"Project"] = "ALL";
dsProjectDetails.Tables[
"ProjectDetails"].Rows.InsertAt(newRow, 0);
}
return dsProjectDetails.Tables["ProjectDetails"];
}
catch
{
throw;
}
}
protected void rCboProject_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
rgDetails.CurrentPageIndex = 0;
rgDetails.Rebind();
}
protected void rgDetails_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
string project = rCboProject.Text;
rgDetails.DataSource = GetTaskDetails(project);
}
private
DataTable GetTaskDetails(string project)
{
try
{
DataSet dsTaskDetails = new DataSet();
//TODO to get the task details
DataTable dtTaskDetails = dsTaskDetails.Tables["TaskDetails"];
return dtTaskDetails;
}
catch
{
throw;
}
}
Thanks and Regards,
S.Santhanamahalingam.