Hello..
can anyone help me to apply alternative style for gridview merge rows..TQ.
Below is my Javascript and my aspx.cs code
- <script type="text/javascript" lang="javascript">
- var tblId = document.getElementById('<%=gvUpdateDate.ClientID%>');
- var rows = tblId.getElementsByTagName("tr");
- var clsName = '';
- var str = '';
- for (i = 1; i < rows.length; i++) {
-
- if (rows[i].getElementsByTagName("td").length == 3) {
- if (str == '') {
- str = i;
- }
- else {
- str = str + ',' + i;
- }
- }
- }
- var arr = str.split(",");
-
- for (j = 0; j < arr.length; j++) {
- if (j % 2 == 0) {
- rows[arr[j]].className = "even";
- } else {
- rows[arr[j]].className = "odd";
- }
- }
- for (i = 1; i < rows.length; i++) {
- if (rows[i].getElementsByTagName("td").length == 3) {
- clsName = rows[i].className;
- }
- else {
- rows[i].className = clsName;
- }
- }
- </script>
- private void MergeGridviewRows(GridView gridView)
- {
- for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--)
- {
- GridViewRow row = gridView.Rows[rowIndex];
- GridViewRow previousRow = gridView.Rows[rowIndex + 1];
- if (row.Cells[0].Text == previousRow.Cells[0].Text && row.Cells[1].Text == previousRow.Cells[1].Text)
- {
- row.Cells[0].RowSpan = previousRow.Cells[0].RowSpan < 2 ? 2 : previousRow.Cells[0].RowSpan + 1;
- row.Cells[1].RowSpan = previousRow.Cells[1].RowSpan < 2 ? 2 : previousRow.Cells[1].RowSpan + 1;
- previousRow.Cells[0].Visible = false;
- previousRow.Cells[1].Visible = false;
- }
- if (row.Cells[2].Text == previousRow.Cells[2].Text && row.Cells[3].Text == previousRow.Cells[3].Text)
- {
- row.Cells[2].RowSpan = previousRow.Cells[2].RowSpan < 2 ? 2 : previousRow.Cells[2].RowSpan + 1;
- row.Cells[3].RowSpan = previousRow.Cells[3].RowSpan < 2 ? 2 : previousRow.Cells[3].RowSpan + 1;
- previousRow.Cells[2].Visible = false;
- previousRow.Cells[3].Visible = false;
- }
- if (row.Cells[4].Text == previousRow.Cells[4].Text && row.Cells[5].Text == previousRow.Cells[5].Text)
- {
- row.Cells[4].RowSpan = previousRow.Cells[4].RowSpan < 2 ? 2 : previousRow.Cells[4].RowSpan + 1;
- row.Cells[5].RowSpan = previousRow.Cells[5].RowSpan < 2 ? 2 : previousRow.Cells[5].RowSpan + 1;
- previousRow.Cells[4].Visible = false;
- previousRow.Cells[5].Visible = false;
- }
- }
- }
- protected void gvUpdateDate_PreRender(object sender, EventArgs e)
- {
- MergeGridviewRows(gvUpdateDate);
- }