You could try something like this. This example was checks for the value in the first column when a row is selected, but you could do something similar with the edit row. I started at the selected row, then searched through the rows (moving up the table)
until a row is found with the right number of cells, then grab the value.
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
int index = GridView1.SelectedIndex;
int columnCount = GridView1.Columns.Count;
for (int i = index; i >= 0; i--)
{
GridViewRow row = GridView1.Rows[i];
int cellCount = row.Cells.Count;
if (cellCount == columnCount)
{
Label1.Text = row.Cells[0].Text;
break;
}
}
}
Hope that helps.
Aaron
Don't forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so everyone will know you have been helped.
agolden
Star
7893 Points
1060 Posts
Re: Merge Cell in GridView
Feb 01, 2007 01:18 AM|LINK
You could try something like this. This example was checks for the value in the first column when a row is selected, but you could do something similar with the edit row. I started at the selected row, then searched through the rows (moving up the table) until a row is found with the right number of cells, then grab the value.
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { int index = GridView1.SelectedIndex; int columnCount = GridView1.Columns.Count; for (int i = index; i >= 0; i--) { GridViewRow row = GridView1.Rows[i]; int cellCount = row.Cells.Count; if (cellCount == columnCount) { Label1.Text = row.Cells[0].Text; break; } } }Hope that helps.
Aaron