c# - Merge duplicate values from a gridview in asp.net -
i have 2 gridview's in page (gridview inside gridview) in main gridview want merge duplicate values of first cells. binding both gridview @ runtime. please help
aspx:
<asp:gridview id="maingridview" runat="server" autogeneratecolumns="true" showfooter="true" skinid="gridviewmast" emptydatatext="no records found." rowstyle-wrap="true" alternatingrowstyle-wrap="true" cellpadding="6" onrowdatabound="maingridview_rowdatabound" onrowcreated="maingridview_rowcreated"> <columns> <asp:templatefield headertext="action item" itemstyle-horizontalalign="left" itemstyle-wrap="false"> <itemtemplate> <asp:gridview id="grditemnested" runat="server" allowpaging="true"> <columns> </columns> <headerstyle backcolor="#5d7b9d" forecolor="white" height="30px" font-bold="true" /> <rowstyle height="20px" backcolor="#ffffff" forecolor="#000000" /> <alternatingrowstyle backcolor="#d3d3d3" forecolor="#000000" /> <footerstyle backcolor="#5d7b9d" forecolor="white" height="30px" font-bold="true" /> </asp:gridview> </itemtemplate> <itemstyle horizontalalign="center" verticalalign="top"></itemstyle> </asp:templatefield> </columns> <emptydatarowstyle height="25px" font-bold="true" /> <rowstyle height="20px" /> <pagerstyle height="30px" /> <headerstyle height="30px" font-bold="true" /> <footerstyle height="30px" font-bold="true" /> </asp:gridview>
am using ondatabound event achieve when running application first record merge in gridview , alignment not proper of main gridview. can please me rectify missing here.
.cs
protected void maingridview_databound1(object sender, eventargs e) { (int rowindex = maingridview.rows.count - 2; rowindex >= 0; rowindex--) { gridviewrow gvrow = maingridview.rows[rowindex]; gridviewrow gvpreviousrow = maingridview.rows[rowindex + 1]; (int cellcount = 0; cellcount < gvrow.cells.count; cellcount++) { if (gvrow.cells[cellcount].text == gvpreviousrow.cells[cellcount].text) { if (gvpreviousrow.cells[cellcount].rowspan < 2) { gvrow.cells[cellcount].rowspan = 2; } else { gvrow.cells[cellcount].rowspan = gvpreviousrow.cells[cellcount].rowspan + 1; } gvpreviousrow.cells[cellcount].visible = false; } } } }
Comments
Post a Comment