Hi I dynamically generate the columns in a grid and then load and bind a datasource, everything looks good until I press the column header to sort the grid, the grid does not sort and the column headers disappear. What Am I missing:
The grid declaration:
Clicking a button loads the grid the first time:
The Code:
The ourput of the GetReport Call is a business object with properties that match the column names and here is the sort command procedure:
I can't see anything amiss that would cause this issue. I'm currently not using any type of AJAX management on the page.
Thanks in Advance
Jonathan
The grid declaration:
<
telerik:RadGrid
ID
=
"radGridOutput"
runat
=
"server"
AllowPaging
=
"True"
Width
=
"100%"
enableEmbeddedSkins
=
"false"
Skin
=
"CorpsNET"
AllowSorting
=
"true"
pagesize
=
"10"
ClientSettings-AllowKeyboardNavigation
=
"false"
ItemStyle-HorizontalAlign
=
"Center"
HeaderStyle-HorizontalAlign
=
"Center"
AlternatingItemStyle-HorizontalAlign
=
"Center"
onpageindexchanged
=
"radGridOutput_PageIndexChanged"
onsortcommand
=
"radGridOutput_SortCommand"
onitemdatabound
=
"radGridOutput_ItemDataBound"
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
<
MasterTableView
AutoGenerateColumns
=
"false"
Width
=
"100%"
CommandItemDisplay
=
"None"
PageSize
=
"10"
>
<
Columns
>
</
Columns
>
<
EditFormSettings
>
<
PopUpSettings
ScrollBars
=
"None"
/>
</
EditFormSettings
>
<
NoRecordsTemplate
>
<
div
align
=
"center"
style
=
"color:darkorange"
>---------- No Records to Display -----------</
div
>
</
NoRecordsTemplate
>
</
MasterTableView
>
<
ClientSettings
>
</
ClientSettings
>
</
telerik:RadGrid
>
protected void btnCreateReport_Click(object sender, EventArgs e)
{
LoadReport(true);
RadTabStrip1.SelectedIndex = 1;
RadMultiPage1.SelectedIndex = 1;
}
The Code:
protected void LoadReport(bool firstLoad)
{
//if we are paging or sorting don't erase the columns
if (firstLoad == true)
{
radGridOutput.DataSource = null;
radGridOutput.MasterTableView.DataKeyNames = null;
radGridOutput.MasterTableView.Columns.Clear();
radGridOutput.Columns.Clear();
}
if (firstLoad == true)
{
radGridOutput.MasterTableView.AutoGenerateColumns = false;
radGridOutput.AutoGenerateColumns = false;
//string[] _keys3 = { "ID" };
//radGridOutput.MasterTableView.DataKeyNames = _keys3;
radGridOutput.Columns.Add(new GridBoundColumn() { UniqueName = "RosterDate", DataField = "RosterDateString", HeaderText = "Date", SortExpression = "RosterDate" });
radGridOutput.Columns.Add(new GridBoundColumn() { UniqueName = "RosterDay", DataField = "RosterDay", HeaderText = "Day" });
radGridOutput.Columns.Add(new GridBoundColumn() { UniqueName = "SponsorNumberAndName", DataField = "SponsorNumberAndName", HeaderText = "Sponsor", SortExpression = "SponsorNumberAndName" });
radGridOutput.Columns.Add(new GridBoundColumn() { UniqueName = "LocationNumberAndName", DataField = "LocationNumberAndName", HeaderText = "Location", SortExpression = "LocationNumberAndName" });
radGridOutput.Columns.Add(new GridBoundColumn() { UniqueName = "CrewName", DataField = "CrewName", HeaderText = "Crew", SortExpression = "CrewName" });
radGridOutput.Columns.Add(new GridBoundColumn() { UniqueName = "SupervisorName", DataField = "SupervisorName", HeaderText = "Supervisor", SortExpression = "SupervisorName" });
radGridOutput.Columns.Add(new GridBoundColumn() { UniqueName = "NumberOfCrewmembers", DataField = "NumberOfCrewmembers", HeaderText = "# Crew Members", SortExpression = "NumberOfCrewmembers" });
radGridOutput.Columns.Add(new GridBoundColumn() { UniqueName = "TotalHours", DataField = "totalhours", HeaderText = "Total Hours", SortExpression = "totalHours" });
}
if (rdoPayPeriod.Checked == true)
{
PayPeriod _payPeriod = PayPeriodService.GetByID(Int32.Parse(ddlPayPeriod.SelectedValue.ToString()));
radGridOutput.DataSource = RptProjectHoursDetailService.GetReport(_payPeriod.StartDate, _payPeriod.EndDate, ddlSponsor.SelectedIndex>0?Int32.Parse(ddlSponsor.SelectedValue.ToString()):0);
}
else if (rdoSchoolMonth.Checked == true)
{
SchoolMonth _schoolMonth = SchoolMonthService.GetByID(Int32.Parse(ddlSchoolMonth.SelectedValue.ToString()));
radGridOutput.DataSource = RptProjectHoursDetailService.GetReport(_schoolMonth.StartDate, _schoolMonth.EndDate, ddlSponsor.SelectedIndex > 0 ? Int32.Parse(ddlSponsor.SelectedValue.ToString()) : 0);
}
else if (rdoSpecifiedTimePeriod.Checked == true)
{
radGridOutput.DataSource = RptProjectHoursDetailService.GetReport(DateTime.Parse(rdpStartDate.DbSelectedDate.ToString()), DateTime.Parse(rdpEndDate.DbSelectedDate.ToString()), ddlSponsor.SelectedIndex > 0 ? Int32.Parse(ddlSponsor.SelectedValue.ToString()) : 0);
}
radGridOutput.DataBind();
}
The ourput of the GetReport Call is a business object with properties that match the column names and here is the sort command procedure:
protected void radGridOutput_SortCommand(object source, GridSortCommandEventArgs e)
{
LoadReport(false);
}
I can't see anything amiss that would cause this issue. I'm currently not using any type of AJAX management on the page.
Thanks in Advance
Jonathan