问题:如果有数据
星期一 12节 课程1 100
星期一 12节 课程2 99
星期一 34节 课程3 89
星期一 34节 课程4 99
星期一 34节 课程4 89
星期一 34节 课程5 89我想要的数据为
12 课程1 100
节 课程2 99
星 课程3 89
期 34 课程4 99
一 节 课程4 89
课程5 89
在asp.net2.0 vs2005(c#)datagrid里面实现
星期一 12节 课程1 100
星期一 12节 课程2 99
星期一 34节 课程3 89
星期一 34节 课程4 99
星期一 34节 课程4 89
星期一 34节 课程5 89我想要的数据为
12 课程1 100
节 课程2 99
星 课程3 89
期 34 课程4 99
一 节 课程4 89
课程5 89
在asp.net2.0 vs2005(c#)datagrid里面实现
int row = 0;
int row_1 = 0;
int order;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (RadioButtonList1.SelectedIndex == 1 && e.Row.Cells[5].Text == "总计")
{
e.Row.Font.Bold = true;
//e.Row.ForeColor = System.Drawing.Color.White;
e.Row.BackColor = System.Drawing.Color.LightBlue;
}
if (e.Row.RowType != DataControlRowType.Footer && e.Row.RowType != DataControlRowType.Header) //页脚
{
if (RadioButtonList1.SelectedIndex == 5 )
{
int rowindex = e.Row.RowIndex;
if (rowindex - 1 < 0)
{
order = order + 1;
e.Row.Cells[0].Text = order.ToString();
return;
}
if (e.Row.Cells[1].Text == GridView1.Rows[rowindex - 1].Cells[1].Text)
{
if (GridView1.Rows[row].Cells[0].RowSpan == 0) GridView1.Rows[row].Cells[0].RowSpan++;
GridView1.Rows[row].Cells[0].RowSpan++;
e.Row.Cells[0].Visible = false;
if (GridView1.Rows[row].Cells[1].RowSpan == 0) GridView1.Rows[row].Cells[1].RowSpan++;
GridView1.Rows[row].Cells[1].RowSpan++;
e.Row.Cells[1].Visible = false;
if (GridView1.Rows[row].Cells[2].RowSpan == 0) GridView1.Rows[row].Cells[2].RowSpan++;
GridView1.Rows[row].Cells[2].RowSpan++;
e.Row.Cells[2].Visible = false;
if (GridView1.Rows[row].Cells[3].RowSpan == 0) GridView1.Rows[row].Cells[3].RowSpan++;
GridView1.Rows[row].Cells[3].RowSpan++;
e.Row.Cells[3].Visible = false; if (GridView1.Rows[row].Cells[4].RowSpan == 0) GridView1.Rows[row].Cells[4].RowSpan++;
GridView1.Rows[row].Cells[4].RowSpan++;
e.Row.Cells[4].Visible = false;
if (GridView1.Rows[row].Cells[5].RowSpan == 0) GridView1.Rows[row].Cells[5].RowSpan++;
GridView1.Rows[row].Cells[5].RowSpan++;
e.Row.Cells[5].Visible = false;
if (GridView1.Rows[row].Cells[6].RowSpan == 0) GridView1.Rows[row].Cells[6].RowSpan++;
GridView1.Rows[row].Cells[6].RowSpan++;
e.Row.Cells[6].Visible = false;
if (GridView1.Rows[row].Cells[7].RowSpan == 0) GridView1.Rows[row].Cells[7].RowSpan++;
GridView1.Rows[row].Cells[7].RowSpan++;
e.Row.Cells[7].Visible = false;
if (GridView1.Rows[row].Cells[8].RowSpan == 0) GridView1.Rows[row].Cells[8].RowSpan++;
GridView1.Rows[row].Cells[8].RowSpan++;
e.Row.Cells[8].Visible = false;
if (GridView1.Rows[row].Cells[9].RowSpan == 0) GridView1.Rows[row].Cells[9].RowSpan++;
GridView1.Rows[row].Cells[9].RowSpan++;
e.Row.Cells[9].Visible = false;
}
else
{
row = rowindex;
order = order + 1;
e.Row.Cells[0].Text = order.ToString();
}
}
else
{
if (RadioButtonList1.SelectedIndex == 8)
{ int rowindex = e.Row.RowIndex;
int rowindex_1 = e.Row.RowIndex;
if (rowindex - 1 < 0 && rowindex_1 - 1 < 0)
{
order = order + 1;
e.Row.Cells[0].Text = order.ToString();
return;
}
/*if (GridView1.Rows[rowindex].Cells[1].RowSpan == 0) GridView1.Rows[rowindex].Cells[1].RowSpan++;
GridView1.Rows[rowindex].Cells[1].RowSpan++;
e.Row.Cells[1].Visible = false;*/
if (e.Row.Cells[2].Text == GridView1.Rows[rowindex - 1].Cells[2].Text)
{
if (GridView1.Rows[row].Cells[2].RowSpan == 0) GridView1.Rows[row].Cells[2].RowSpan++;
GridView1.Rows[row].Cells[2].RowSpan++;
e.Row.Cells[2].Visible = false;
}
else
{
row = rowindex;
}
if (e.Row.Cells[1].Text == GridView1.Rows[rowindex_1 - 1].Cells[1].Text)
{
if (GridView1.Rows[row_1].Cells[1].RowSpan == 0) GridView1.Rows[row_1].Cells[1].RowSpan++;
GridView1.Rows[row_1].Cells[1].RowSpan++;
e.Row.Cells[1].Visible = false;
}
else
{ row_1 = rowindex_1;
}
}
order = order + 1;
e.Row.Cells[0].Text = order.ToString();
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{ e.Row.Cells[1].Attributes.Add("class", "text"); }
}
这是我去年用C#写的,也是网上看来的
看
RadioButtonList1.SelectedIndex == 5
和RadioButtonList1.SelectedIndex == 8
这两段,分别是两张不同的报表的单元格合并
你可以从网上搜索一下!
例如:ComponentOne0404