Merging Cell Of GridView

Posted by Shoyebaziz123 under ASP.NET on 5/3/2010 | Views : 5229 | Status : [Member] | Replies : 5
Hi All,

Can anybody Help me for showing this type of GridView


Finished Product Batch Size Batch Volume Exp.Yield % PackSize Quantity Volume Yield Volume

BENADRYL COUGH SYRUP 1000Ltr. 1000000ml 96% 200 ml 1000 200000 960000
100 ml 2000 300000
50 ml 200 10000

ZINCOVIT SYRUP 500Ltr. 500000ml. 98% 200 ml 450 11000 490000
100 ml 300 13400
250 ml 400 15000




Responses

Posted by: Vuyiswamb on: 5/3/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
if you are showing us Sample Data, then you have to do better, try to arrange the data correctly so that we can know which column is which


Thank you for posting at Dotnetfunda
[Administrator]

Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 5/3/2010 [Member] Bronze

Up
0
Down
I guess you need to display the data in a gridview with different styles by merging cells. Actually you have to arrange that once the data is bound.

Refer the following link for more info
http://forums.asp.net/p/1053747/1494505.aspx

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Er.deepakdalal on: 5/3/2010 [Member] Starter

Up
0
Down
Hi Shoyebaziz123

Find the attached sample project i found on the code project website it really help me, i hope it will sole your problem also.


 Download source file

Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naveenmanam on: 5/4/2010 [Member] Starter

Up
0
Down
Try this:

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex == 0)
e.Row.Cells[0].RowSpan = ((DataTable)GridView1.DataSource).Rows.Count;
else
e.Row.Cells.Remove(e.Row.Cells[0]);
}

}

protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("this");
dt.Columns.Add("is");
dt.Columns.Add("a");
dt.Columns.Add("test");

DataRow dr = dt.NewRow();
dr["this"] = "data";
dr["is"] = "data";
dr["a"] = "data";
dr["test"] = "data";
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["this"] = "data";
dr["is"] = "data";
dr["a"] = "data";
dr["test"] = "data";
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["this"] = "data";
dr["is"] = "data";
dr["a"] = "data";
dr["test"] = "data";
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["this"] = "data";
dr["is"] = "data";
dr["a"] = "data";
dr["test"] = "data";
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["this"] = "data";
dr["is"] = "data";
dr["a"] = "data";
dr["test"] = "data";
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["this"] = "data";
dr["is"] = "data";
dr["a"] = "data";
dr["test"] = "data";
dt.Rows.Add(dr);

GridView1.DataSource = dt;
GridView1.DataBind();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="This" HeaderText="This" />
<asp:BoundField DataField="Is" HeaderText="Is" />
<asp:BoundField DataField="A" HeaderText="A" />
<asp:BoundField DataField="Test" HeaderText="Test" />
</Columns>
</asp:GridView>
</form>
</body>
</html>

Hope that helps



NaveenKumar

Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naveenmanam on: 5/4/2010 [Member] Starter

Up
0
Down
Try this:

<%@ Page Language="C#" %>

<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex == 0)
e.Row.Cells[0].RowSpan = ((DataTable)GridView1.DataSource).Rows.Count;
else
e.Row.Cells.Remove(e.Row.Cells[0]);
}

}

protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("this");
dt.Columns.Add("is");
dt.Columns.Add("a");
dt.Columns.Add("test");

DataRow dr = dt.NewRow();
dr["this"] = "data";
dr["is"] = "data";
dr["a"] = "data";
dr["test"] = "data";
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["this"] = "data";
dr["is"] = "data";
dr["a"] = "data";
dr["test"] = "data";
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["this"] = "data";
dr["is"] = "data";
dr["a"] = "data";
dr["test"] = "data";
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["this"] = "data";
dr["is"] = "data";
dr["a"] = "data";
dr["test"] = "data";
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["this"] = "data";
dr["is"] = "data";
dr["a"] = "data";
dr["test"] = "data";
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["this"] = "data";
dr["is"] = "data";
dr["a"] = "data";
dr["test"] = "data";
dt.Rows.Add(dr);

GridView1.DataSource = dt;
GridView1.DataBind();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="This" HeaderText="This" />
<asp:BoundField DataField="Is" HeaderText="Is" />
<asp:BoundField DataField="A" HeaderText="A" />
<asp:BoundField DataField="Test" HeaderText="Test" />
</Columns>
</asp:GridView>
</form>
</body>
</html>


Hope that helps



NaveenKumar

Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response