TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Hazel Mahmud
1.4k
315
70k
apply alternative style for gridview merge rows
May 28 2021 4:35 PM
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++) {
//get the rows which have all cells
if
(rows[i].getElementsByTagName(
"td"
).length == 3) {
if
(str ==
''
) {
str = i;
}
else
{
str = str +
','
+ i;
}
}
}
var
arr = str.split(
","
);
//find merge rows and apply parent style on merge rows
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);
}
Reply
Answers (
1
)
Refresh DataTable on Update
How To Map Web Application To LIFF