我正在使用Telerik RadGrid并且有一个我能够实现的要求,但它似乎不能按我预期的方式工作。
要求: 单击一个按钮添加父标题行(加载5个记录),然后单击另一个按钮删除(加载更多记录)
网格声明如下
<telerik:RadGrid ID="rgDetails1" runat="server" Width="99.9%" Skin="Office2010Blue"
EnableEmbeddedSkins="true" AutoGenerateColumns="true" OnColumnCreated="rgDetails1_ColumnCreated">
<MasterTableView DataKeyNames="RowID" TableLayout="Fixed" HeaderStyle-Height="28px">
<NoRecordsTemplate>
<asp:Label ID="lblError" runat="server" Text="No records to display."></asp:Label></NoRecordsTemplate>
</MasterTableView>
<ClientSettings>
<Resizing AllowColumnResize="True" />
<Scrolling AllowScroll="true" ScrollHeight="280px" UseStaticHeaders="true"></Scrolling>
<ClientEvents OnGridCreated="GridCreated" />
</ClientSettings>
</telerik:RadGrid>
并且Grid与以下代码绑定
protected void btnLoad1_Click(object sender, EventArgs e)
{
DataTable fdtObjDetails = null;
try
{
fdtObjDetails = LoadData(5);
GridColumnGroup parentHeader = new GridColumnGroup();
parentHeader.HeaderText = "Essential";
parentHeader.Name = "Group1";
parentHeader.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
rgDetails1.MasterTableView.ColumnGroups.Add(parentHeader);
rgDetails1.DataSource = fdtObjDetails;
rgDetails1.DataBind();
}
catch (Exception objExcep)
{
string fstrError = objExcep.ToString();
}
}
并完成RadGrid分组的Column Created事件。
protected void rgDetails1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
try
{
if (e.Column.HeaderText != "" && e.Column.HeaderText != string.Empty && e.Column.HeaderText != null)
{
e.Column.ItemStyle.Height = System.Web.UI.WebControls.Unit.Pixel(20);
switch (e.Column.HeaderText.ToUpper())
{
case "ROWID":
case "ROW ID":
e.Column.Visible = false;
break;
case "TYPE":
e.Column.HeaderText = "Type";
e.Column.UniqueName = "Type";
e.Column.HeaderStyle.Width = System.Web.UI.WebControls.Unit.Pixel(100);
e.Column.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
e.Column.HeaderStyle.VerticalAlign = VerticalAlign.Middle;
e.Column.ColumnGroupName = "Group1";
break;
case "FLIGHT NAME":
case "FLIGHT_NAME":
{
e.Column.HeaderText = "Flight Name";
e.Column.UniqueName = "Flight_Name";
e.Column.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
e.Column.HeaderStyle.VerticalAlign = VerticalAlign.Middle;
e.Column.ColumnGroupName = "Group1";
break;
}
case "LIVES":
{
e.Column.HeaderText = "Lives";
e.Column.UniqueName = "Lives";
GridBoundColumn _GridColumn = (GridBoundColumn)e.Column;
e.Column.HeaderStyle.Width = System.Web.UI.WebControls.Unit.Pixel(60);
e.Column.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
e.Column.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
e.Column.HeaderStyle.VerticalAlign = VerticalAlign.Middle;
_GridColumn.DataFormatString = "{0:#,###}";
e.Column.ColumnGroupName = "Group1";
break;
}
}
}
}
catch (Exception objExcep)
{
string fstrClsNm = "AL-CLS" + this.GetType().BaseType.FullName + "-rgDetails1_ColumnCreated()";
}
}
现在问题是,只要我点击任何一个按钮,我就会收到以下错误。
我该如何解决这个问题?或者有没有其他方法来添加看起来类似于上图的标题行?