Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
how to get the serial number for datagridview rows
Posted
Comments
sanjeev1.bhambra@gmail.com 25-Apr-12 5:48am    
Hi ,

This code does not works for merged rows.I want to get the Serial number for Merged rows. For example there 3 colums C1(seria no),C2,C3. For one value of C2 there is multiple values of C3. Therefore I have merged C2 for same values. But I am not able to get serial number for C2.

I am using below code for Merging the C2 for same values:

protected void GrdReportingDetails_PreRender(object sender, EventArgs e)
{
GridDecorator.MergeRows(GrdReportingDetails);
}
}


public class GridDecorator
{
public static void MergeRows(GridView gridView)
{
for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--)
{
GridViewRow row = gridView.Rows[rowIndex];
GridViewRow previousRow = gridView.Rows[rowIndex + 1];

for (int i = 1; i < row.Cells.Count; i++)
{
if (row.Cells[i].Text == previousRow.Cells[i].Text)
{
row.Cells[i].RowSpan = previousRow.Cells[i].RowSpan < 2 ? 2 :
previousRow.Cells[i].RowSpan + 1;
previousRow.Cells[i].Visible = false;
}
}
}
}
}

Hi
ASP.NET
<asp:gridview runat=""server"" id=""gvDemo"" xmlns:asp="#unknown">
 <columns>
 <asp:templatefield>
 <itemtemplate>
 <%#Container.DataItemIndex+1 %>
 </itemtemplate>
 </asp:templatefield>
</columns>
 </asp:gridview>


For Example

http://www.dotnetexpertsforum.com/how-to-add-serial-number-column-to-gridview-in-asp-net-t229.html

thnx
 
Share this answer
 
You can use
C#
DataItemIndex
or
C#
RowIndex
property of grid view row to achieve the same
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900