其实代码本来是多表头合并的,这里只做了一层~ 哦哈哈
====================================================================
前台页面代码
class="code_img_closed" style="display: none;" src="/Upload/Images/2013073115/0015B68B3C38AA5B.gif" alt="" />
logs_code_hide('dad766a5-d07c-42b9-9945-e0f587e14e66',event)" src="/Upload/Images/2013073115/2B1B950FA3DF188F.gif" alt="" />
前台
<%@ Page Language=
"C#" MasterPageFile=
"~/Master/DefaultPage.master" AutoEventWireup=
"true" CodeFile=
"PerformanceIndicator.aspx.cs" Inherits=
"PerformanceWarning_PerformanceIndicator" Title=
"无标题页" %>
<%@ Register Assembly=
"RadAjax.Net2" Namespace=
"Telerik.WebControls" TagPrefix=
"radA" %>
<%@ Register Assembly=
"RadGrid.Net2" Namespace=
"Telerik.WebControls" TagPrefix=
"radG" %>
<%@ Register TagPrefix=
"radW" Namespace=
"Telerik.WebControls" Assembly=
"RadWindow.Net2" %>
<%@ Register TagPrefix=
"radCln" Namespace=
"Telerik.WebControls" Assembly=
"RadCalendar.NET2" %>
<asp:Content ID=
"Content1" ContentPlaceHolderID=
"ContentPlaceHolder1" Runat=
"Server">
<radW:RadWindowManager ID=
"Singleton" runat=
"server" ClientCallBackFunction=
"CallBackFunction" OnClientClose=
"OnClientClose" OnClientShow=
"OnClientShow">
<Windows>
<radW:RadWindow ID=
"DialogWindow2" runat=
"server" Height=
"400px" Modal=
"true" Width=
"740px" />
</Windows>
</radW:RadWindowManager>
<radA:RadAjaxManager ID=
"RadAjaxManager1" runat=
"server">
<AjaxSettings>
</AjaxSettings>
</radA:RadAjaxManager>
<table border=
"0" >
<tr valign=
"top">
<td valign=
"middle" >
考核起止日期:</td>
<td > <radCln:RadDatePicker ID=
"txtMinDate" runat=
"server" AutoPostBack=
"false" >
<DateInput DateFormat=
"D" ReadOnly=
"true">
</DateInput><DatePopupButton Title=
"点击后弹出日期选择框"></DatePopupButton>
</radCln:RadDatePicker></td>
<td valign=
"middle" > - </td>
<td > <radCln:RadDatePicker ID=
"txtMaxDate" runat=
"server" AutoPostBack=
"false">
<DateInput DateFormat=
"D" ReadOnly=
"true">
</DateInput><DatePopupButton Title=
"点击后弹出日期选择框"></DatePopupButton>
</radCln:RadDatePicker> </td>
<td valign=
"middle" >
<asp:Button ID=
"btnQuery" runat=
"server" SkinID=
"SearchBtn" OnClick=
"btnQuery_Click" >
</asp:Button>
</td>
</tr>
</table> <br />
<div style=
"text-align: left"> <strong>查询列表:</strong></div>
<radG:RadGrid ID=
"rgData" runat=
"server" AllowPaging=
"false" AllowMultiRowSelection=
"True" Width=
"100%" AutoGenerateColumns=
"false" EnableAJAX=
"false" GridLines=
"None" ShowStatusBar=
"False" AllowCustomPaging=
"False" PageSize=
"15" OnNeedDataSource=
"rgData_NeedDataSource" OnItemDataBound=
"rgData_ItemDataBound" OnItemCreated=
"rgData_OnItemCreate">
<ClientSettings ReorderColumnsOnClient=
"True" AllowColumnsReorder=
"False">
<Selecting AllowRowSelect=
"True" />
<Scrolling UseStaticHeaders=
"True" />
<Resizing EnableRealTimeResize=
"True" />
<ClientMessages DragToResize=
"调整大小" DropHereToReorder=
"移动列到此位置" DragToGroupOrReorder=
"按住不放移动列">
</ClientMessages>
</ClientSettings>
<HeaderStyle HorizontalAlign=
"Center" />
<ItemStyle HorizontalAlign=
"Center" />
<AlternatingItemStyle HorizontalAlign=
"Center" />
<MasterTableView NoMasterRecordsText=
"没有数据." DataKeyNames=
"JXZBMS" AllowSorting=
"False" AllowMultiColumnSorting=
"True" Width=
"100%">
<Columns>
</Columns>
<PagerStyle Mode=
"NextPrevAndNumeric" PagerTextFormat=
"{4} &nbsp;&nbsp;&nbsp;&nbsp; (第 {0} 页 / 共 {1} 页, 第 {2} 条 至 第 {3} 条, 总共 {5} 条)" HorizontalAlign=
"Right" />
<ExpandCollapseColumn Visible=
"False">
<HeaderStyle Width=
"19px" />
</ExpandCollapseColumn>
<RowIndicatorColumn Visible=
"False">
<HeaderStyle Width=
"20px" />
</RowIndicatorColumn>
</MasterTableView>
<StatusBarSettings LoadingText=
"读取中..." ReadyText=
"完成" />
</radG:RadGrid>
</asp:Content>
后台页面代码
后台代码
using System;
using System.Collections;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using xxx.BLL;
using xxx.Model;
using Telerik.WebControls;
public partial class PerformanceWarning_PerformanceIndicator : System.Web.UI.Page
{
private ArrayList arrHeaderCellsOne =
null;
private ArrayList arrHeaderCellsTwo =
null;
private ArrayList arrHeaderCells
Three =
null;
private Hashtable hiddenColumn =
new Hashtable();
protected void Page_Load(
object sender, EventArgs e)
{
MergeGrid();
}
protected void btnQuery_Click(
object sender, EventArgs e)
{
rgData.Rebind();
//重新绑定数据 }
public class LabelColumn : ITemplate
{
private string lblID;
public LabelColumn()
{
// 'Add constructor stuff here
}
public LabelColumn(
string lblID)
{
this.lblID = lblID;
// 'Add constructor stuff here
}
public void InstantiateIn(Control container)
{
Label label =
new Label();
label.DataBinding +=
new EventHandler(
this.BindLabelColumn);
container.Controls.Add(label);
label.ID = lblID;
}
public void BindLabelColumn(
object sender, EventArgs e)
{
Label label = (Label)sender;
Telerik.WebControls.GridItem container = (GridItem)label.NamingContainer;
label.Text = Convert.ToString(container.ItemIndex +
1);
}
}
public class TextBoxColumn : ITemplate
{
private string txtID;
public TextBoxColumn()
{
// 'Add constructor stuff here
}
public TextBoxColumn(
string txtID)
{
this.txtID = txtID;
// 'Add constructor stuff here
}
public void InstantiateIn(Control container)
{
TextBox txtbox =
new TextBox();
txtbox.DataBinding +=
new EventHandler(
this.BindTextBoxColumn);
container.Controls.Add(txtbox);
txtbox.ID = txtID;
}
public void BindTextBoxColumn(
object sender, EventArgs e)
{
TextBox txtbox = (TextBox)sender;
Telerik.WebControls.GridItem container = (GridItem)txtbox.NamingContainer;
txtbox.Text =
"0";
}
}
private void MergeGrid()
{
rgData.Columns.Clear();
ArrayList arrColumnID =
new ArrayList();
ArrayList arrColumnName =
new ArrayList();
ArrayList arrScale =
new ArrayList();
hiddenColumn.Clear();
int maxRowSpan =
1;
//最大行距
int columnNo =
0;
//列号
ArrayList
headerOne =
new ArrayList();
ArrayList headerTwo =
new ArrayList();
ArrayList headerThree =
new ArrayList();
if (maxRowSpan >
1)
{
hiddenColumn.Add(
0,
0);
hiddenColumn.Add(
1,
1);
}
TableCell cellDefault =
new TableCell();
cellDefault.Text =
"序号";
cellDefault.RowSpan =
1;
cellDefault.ColumnSpan =
1;
cellDefault.CssClass =
"MasterTable_Windows_Eric_001";
cellDefault.Wrap =
false;
//cellDefault.Width = Unit.Pixel(36);
cellDefault.HorizontalAlign = HorizontalAlign.Center;
headerOne.Add(cellDefault);
columnNo =
0;
GridTemplateColumn xuhaoCol =
new GridTemplateColumn();
xuhaoCol.ItemTemplate =
new LabelColumn(
"Index");
rgData.Columns.Add(xuhaoCol);
cellDefault =
new TableCell();
cellDefault.Text =
"绩效指标内容";
cellDefault.RowSpan = maxRowSpan;
cellDefault.ColumnSpan =
1;
cellDefault.CssClass =
"MasterTable_Windows_Eric_001";
cellDefault.Wrap =
false;
cellDefault.HorizontalAlign = HorizontalAlign.Center;
headerOne.Add(cellDefault);
columnNo++;
GridBoundColumn Col1 =
new GridBoundColumn();
Col1.DataField =
"JXZBMS";
rgData.Columns.Add(Col1);
cellDefault =
new TableCell();
cellDefault.Text =
"绩效指标";
cellDefault.RowSpan = maxRowSpan;
cellDefault.ColumnSpan =
1;
cellDefault.CssClass =
"MasterTable_Windows_Eric_001";
cellDefault.Wrap =
false;
cellDefault.HorizontalAlign = HorizontalAlign.Center;
headerOne.Add(cellDefault);
columnNo++;
GridBoundColumn Col2 =
new GridBoundColumn();
Col2.DataField =
"JXZB";
Col2.DataFormatString =
"{0:P4}";
rgData.Columns.Add(Col2);
cellDefault =
new TableCell();
cellDefault.Text =
"指标分项内容";
cellDefault.RowSpan = maxRowSpan;
cellDefault.ColumnSpan =
2;
cellDefault.CssClass =
"MasterTable_Windows_Eric_001";
cellDefault.Wrap =
false;
cellDefault.HorizontalAlign = HorizontalAlign.Center;
headerOne.Add(cellDefault);
columnNo++;
GridBoundColumn Col3 =
new GridBoundColumn();
Col3.DataField =
"JXZB_FZ_MS";
rgData.Columns.Add(Col3);
GridBoundColumn Col4 =
new GridBoundColumn();
Col4.DataField =
"JXZB_FZ";
rgData.Columns.Add(Col4);
cellDefault =
new TableCell();
cellDefault.Text =
"考核起始日期";
cellDefault.RowSpan = maxRowSpan;
cellDefault.ColumnSpan =
1;
cellDefault.CssClass =
"MasterTable_Windows_Eric_001";
cellDefault.Wrap =
false;
cellDefault.HorizontalAlign = HorizontalAlign.Center;
headerOne.Add(cellDefault);
columnNo++;
GridBoundColumn Col5 =
new GridBoundColumn();
Col5.DataField =
"QSRQ";
Col5.DataFormatString =
"{0:d}";
rgData.Columns.Add(Col5);
cellDefault =
new TableCell();
cellDefault.Text =
"考核终止日期";
cellDefault.RowSpan = maxRowSpan;
cellDefault.ColumnSpan =
1;
cellDefault.CssClass =
"MasterTable_Windows_Eric_001";
cellDefault.Wrap =
false;
cellDefault.HorizontalAlign = HorizontalAlign.Center;
headerOne.Add(cellDefault);
columnNo++;
GridBoundColumn Col6 =
new GridBoundColumn();
Col6.DataField =
"ZZRQ";
Col6.DataFormatString =
"{0:d}";
rgData.Columns.Add(Col6);
ViewState[
"arrColumnID"] = arrColumnID;
ViewState[
"arrColumnName"] = arrColumnName;
ViewState[
"arrScale"] = arrScale;
AddMergeHeader1(headerOne);
AddMergeHeader2(headerTwo);
AddMergeHeader3(headerThree);
}
private void NewRenderMethod(HtmlTextWriter writer, Control ctl)
{
int maxRowSpan =
1;
//最大行距
if (maxRowSpan >
0)
{
if (maxRowSpan ==
1)
{
if (arrHeaderCellsOne !=
null)
{
for (
int i =
0; i < arrHeaderCellsOne.Count; i++)
{
TableCell item = (TableCell)arrHeaderCellsOne[i];
item.CssClass =
"MasterTable_Web20_Eric_001";
item.RenderControl(writer);
}
}
}
if (maxRowSpan ==
2)
{
if (arrHeaderCellsOne !=
null)
{
for (
int i =
0; i < arrHeaderCellsOne.Count; i++)
{
TableCell item = (TableCell)arrHeaderCellsOne[i];
item.CssClass =
"MasterTable_Web20_Eric_001";
item.RenderControl(writer);
}
writer.WriteEndTag(
"TR");
}
if (arrHeaderCellsTwo !=
null)
{
for (
int j =
0; j < arrHeaderCellsTwo.Count; j++)
{
TableCell item = (TableCell)arrHeaderCellsTwo[j];
item.CssClass =
"MasterTable_Web20_Eric_001";
item.RenderControl(writer);
}
}
}
else if (maxRowSpan ==
3)
{
if (arrHeaderCellsOne !=
null)
{
for (
int i =
0; i < arrHeaderCellsOne.Count; i++)
{
TableCell item = (TableCell)arrHeaderCellsOne[i];
item.CssClass =
"MasterTable_Web20_Eric_001";
item.RenderControl(writer);
}
writer.WriteEndTag(
"TR");
}
if (arrHeaderCellsTwo !=
null)
{
for (
int j =
0; j < arrHeaderCellsTwo.Count; j++)
{
TableCell item = (TableCell)arrHeaderCellsTwo[j];
item.CssClass =
"MasterTable_Web20_Eric_001";
item.RenderControl(writer);
}
writer.WriteEndTag(
"TR");
}
if (arrHeaderCellsThree !=
null)
{
for (
int z =
0; z < arrHeaderCellsThree.Count; z++)
{
TableCell item = (TableCell)arrHeaderCellsThree[z];
item.CssClass =
"MasterTable_Web20_Eric_001";
item.RenderControl(writer);
}
}
}
}
}
private void AddMergeHeader1(ArrayList arrHeaderCells)
{
arrHeaderCellsOne = arrHeaderCells;
}
private void AddMergeHeader2(ArrayList arrHeaderCells)
{
arrHeaderCellsTwo = arrHeaderCells;
}
private void AddMergeHeader3(ArrayList arrHeaderCells)
{
arrHeaderCellsThree = arrHeaderCells;
}
protected void rgData_NeedDataSource(
object source, Telerik.WebControls.GridNeedDataSourceEventArgs e)
{
DataTable dt =
new DataTable();
DateTime date1 = txtMinDate.IsEmpty ==
true ? DateTime.Parse(
"1900/1/1") : txtMinDate.SelectedDate.Value;
DateTime date2 = txtMaxDate.IsEmpty ==
true ? DateTime.Parse(
"9999/12/31") : txtMaxDate.SelectedDate.Value;
dt = HengQinDS.BLL.JX_ZB_BLL.GetIndiList(date1, date2);
this.rgData.DataSource = dt;
}
protected void rgData_ItemDataBound(
object sender, Telerik.WebControls.GridItemEventArgs e)
{
if (e.Item.ItemType == Telerik.WebControls.GridItemType.Item || e.Item.ItemType == Telerik.WebControls.GridItemType.AlternatingItem)
{
//序号
Telerik.WebControls.GridTemplateColumn columnXuHao =
new Telerik.WebControls.GridTemplateColumn();
columnXuHao.HeaderStyle.Width = Unit.Pixel(
40);
columnXuHao.ItemStyle.Width = Unit.Pixel(
40);
columnXuHao.HeaderText =
"序号";
columnXuHao.ItemTemplate =
new LabelColumn(
"Index");
rgData.Columns.Add(columnXuHao);
Label lblXuHao = (Label)e.Item.FindControl(
"Index");
int XuHao = rgData.CurrentPageIndex * rgData.PageSize + e.Item.ItemIndex +
1;
lblXuHao.Text = XuHao.ToString();
#region 单元格合并
int previousItemIndex = e.Item.ItemIndex -
1;
if (previousItemIndex >=
0)
{
int num1 =
int.Parse(ViewState[
"Num0"].ToString());
string now = rgData.MasterTableView.DataKey
Values[e.Item.ItemIndex][
"JXZBMS"].ToString();
string old = rgData.MasterTableView.DataKeyValues[previousItemIndex - num1][
"JXZBMS"].ToString();
if (now == old)
{
e.Item.OwnerTableView.Items[previousItemIndex - num1][
"JXZBMS"].RowSpan =
2 + num1;
e.Item.Cells[
3].Visible =
false;
num1++;
ViewState[
"Num0"] = num1.ToString();
}
else {
ViewState[
"Num0"] =
"0";
previousItemIndex = -
1;
}
}
else {
ViewState[
"Num0"] =
"0";
previousItemIndex = -
1;
}
if (previousItemIndex >=
0)
{
int num2 =
int.Parse(ViewState[
"Num1"].ToString());
string now = rgData.MasterTableView.DataKeyValues[e.Item.ItemIndex][
"JXZBMS"].ToString();
string old = rgData.MasterTableView.DataKeyValues[previousItemIndex - num2][
"JXZBMS"].ToString();
if (now == old)
{
e.Item.OwnerTableView.Items[previousItemIndex - num2][
"JXZB"].RowSpan =
2 + num2;
e.Item.Cells[
4].Visible =
false;
num2++;
ViewState[
"Num1"] = num2.ToString();
}
else {
ViewState[
"Num1"] =
"0";
previousItemIndex = -
1;
}
}
else {
ViewState[
"Num1"] =
"0";
previousItemIndex = -
1;
}
previousItemIndex = e.Item.ItemIndex -
1;
if (previousItemIndex >=
0)
{
int num3 =
int.Parse(ViewState[
"Num2"].ToString());
string now = rgData.MasterTableView.DataKeyValues[e.Item.ItemIndex][
"JXZBMS"].ToString();
string old = rgData.MasterTableView.DataKeyValues[previousItemIndex - num3][
"JXZBMS"].ToString();
if (now == old)
{
e.Item.OwnerTableView.Items[previousItemIndex - num3][
"QSRQ"].RowSpan =
2 + num3;
e.Item.Cells[
7].Visible =
false;
num3++;
ViewState[
"Num2"] = num3.ToString();
}
else {
ViewState[
"Num2"] =
"0";
previousItemIndex = -
1;
}
}
else {
ViewState[
"Num2"] =
"0";
}
previousItemIndex = e.Item.ItemIndex -
1;
if (previousItemIndex >=
0)
{
int num4 =
int.Parse(ViewState[
"Num3"].ToString());
string now = rgData.MasterTableView.DataKeyValues[e.Item.ItemIndex][
"JXZBMS"].ToString();
string old = rgData.MasterTableView.DataKeyValues[previousItemIndex - num4][
"JXZBMS"].ToString();
if (now == old)
{
e.Item.OwnerTableView.Items[previousItemIndex - num4][
"ZZRQ"].RowSpan =
2 + num4;
e.Item.Cells[
8].Visible =
false;
num4++;
ViewState[
"Num3"] = num4.ToString();
}
else {
ViewState[
"Num3"] =
"0";
previousItemIndex = -
1;
}
}
else {
ViewState[
"Num3"] =
"0";
}
#endregion }
}
protected void rgData_OnItemCreate(
object sender, GridItemEventArgs e)
{
if (e.Item.ItemType == GridItemType.Header)
{
e.Item.SetRenderMethodDelegate(
new RenderMethod(NewRenderMethod));
}
}
}
出来的效果图
分类