<%@ Page Language="C#"
AutoEventWireup="true"
CodeFile="TestwebPage.aspx.cs"
Inherits="TestwebPage"
%>
DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>merge row
in grid viewtitle>
<script type="text/javascript">
function
Filter(Obj)
{
var
grid=document.getElementById('GridView');
var
terms = Obj.value;
var
cellNr = "0";//grid colunm cellindex in which you want to search
var
ele;
for (var r = 1; r < grid.rows.length; r++)
{
ele =
grid.rows[r].cells[cellNr].innerHTML.replace(/<[^>]+>/g, "");
if
(ele.toLowerCase().indexOf(terms) >= 0)
grid.rows[r].style.display = '';
else
grid.rows[r].style.display = 'none';
}
};
script>
head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="gridView" runat=server CellPadding="2" OnPreRender="gridView_PreRender">asp:GridView>
form>
body>
html>
using System;
using
System.Collections;
using
System.Configuration;
using
System.Data;
using
System.Linq;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.HtmlControls;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Xml.Linq;
using
System.Data.SqlClient;
using
System.Net.Mail;
using System.IO;
using
System.Collections.Generic;
public partial class TestwebPage : System.Web.UI.Page
{
public enum AnalysisType
{ sss, ssss };
protected void Page_Load(object
sender, EventArgs e)
{
if
(!IsPostBack)
{
BindGridView();
}
}
protected void gridView_PreRender(object
sender, EventArgs e)
{
MergeRows(gridView);
}
void
BindGridView()
{
DataSet
dataSet = new DataSet();
gridView.DataSource = dataSet;
gridView.DataBind();
}
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 cellIndex =
0; cellIndex < row.Cells.Count; cellIndex++)
{
if (row.Cells[cellIndex].Text ==
previousRow.Cells[cellIndex].Text)
{
row.Cells[cellIndex].RowSpan =
previousRow.Cells[cellIndex].RowSpan < 2 ? 2 :
previousRow.Cells[cellIndex].RowSpan + 1;
previousRow.Cells[cellIndex].Visible = false;
}
}
}
}
}
No comments :
Post a Comment