private void MergeGridView(GridView grid, int colIndex)
{
int RowSpan = 1;
for (int i = grid.Rows.Count - 1; i > 0; i--)
{
if (grid.Rows[i].Cells[colIndex].Text ==
grid.Rows[i - 1].Cells[colIndex].Text)
{
RowSpan++;
grid.Rows[i - 1].Cells[colIndex].RowSpan = RowSpan;
grid.Rows[i].Cells[colIndex].Visible = false;
}
else
{
RowSpan = 1;
}
}
}
위 코드의 사용법은 그리드뷰 바인딩 후에 셀병합 대상 Gridview id 와 대상 컬럼을 인자로 설정하여
호출하면 원하는 화면을 얻을 수 있다.
화면예제는 생략합니다.
====================================================================================================
위의 방법을 응용하여 Textbox에 담긴 데이터를 병합 할 때에는 아래코드를 이용하면 된다.
private void MergeGridViewTextBox(GridView grid, int colIndex, string textbox)
{
int RowSpan = 1;
for (int i = grid.Rows.Count - 1; i > 0; i--)
{
if (((TextBox)grid.Rows[i].Cells[colIndex].FindControl(textbox)).Text == ((TextBox)grid.Rows[i - 1].Cells[colIndex].FindControl(textbox)).Text)
{
RowSpan++;
grid.Rows[i - 1].Cells[colIndex].RowSpan = RowSpan;
grid.Rows[i].Cells[colIndex].Visible = false;
}
else
{
RowSpan = 1;
}
}
}
음 작업중 문제 발생 !!!!
위 와 같이 할 경우 자바스크립트에서 처리를 할 수 없다.
단순 display:none으로 처리하면 자바스크립트에서 처리가 가능하다. 목적에 맞게 사용하자
public void MergeGridViewTextBox(GridView grid, int colIndex, string textbox)
{
int RowSpan = 1;
for (int i = grid.Rows.Count - 1; i > 0; i--)
{
if (((TextBox)grid.Rows[i].Cells[colIndex].FindControl(textbox)).Text == ((TextBox)grid.Rows[i - 1].Cells[colIndex].FindControl(textbox)).Text)
{
RowSpan++;
grid.Rows[i - 1].Cells[colIndex].RowSpan = RowSpan;
//grid.Rows[i].Cells[colIndex].Visible = false;
grid.Rows[i].Cells[colIndex].Style.Add("display", "none");
}
else
{
RowSpan = 1;
}
}
}


::: 사람과 사람의 교감! 人터넷의 첫 시작! 댓글을 달아주세요! :::