473,473 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Urgent please

Hi,

I need to merge the rows in the datagrid based on the condition.Please
let me know how can i do that.Here is the scenario:

Present View:

Short name Filed by
A P
A Q
A R
B S
B T
B U
C V
C W

But i need to display like this:
Short Name Filed By
A P,Q,R
B S,T,U
C V,W

For that i used itemtemplate in the grid control as below:

<asp:datagrid id="grdRegister" Runat="server"
OnPageIndexChanged="NewPage" Headerstyle-BackColor="#9B9BB4"
Width="100%" HeaderStyle-Font-Bold="True"
HeaderStyle-ForeColor="#000000" HeaderStyle-CssClass="tableheader"
AutoGenerateColumns="False"
Font-Name="verdana">
<AlternatingItemStyle BackColor="#e2e2e2" Font-Name="verdana"
/>
<Columns>
<asp:BoundColumn DataField="Short/Long Entry"
HeaderText="Short/Long Entry" />

<asp:TemplateColumn HeaderText="Filed by">
<ItemTemplate >
<asp:Label runat="server" Text='<%# string.Format( "{0},
{1}",
DataBinder.Eval(Container, "DataItem.Filed By"),
DataBinder.Eval(Container, "DataItem.Short/Long Entry") ) %>'
ID="Label4">
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
Please let me know how can i achieve that.

Thanks,
Vishnu

Nov 10 '06 #1
1 1498
Hi,

You need to create a new DataTable and use it as data source for
GridView:

DataTable table = new DataTable("table");
DataColumn colShortName = new DataColumn("SortName",
Type.GetType("System.String"));
table.Columns.Add(colShortName);
DataColumn colFiledBy = new DataColumn("FiledBy",
Type.GetType("System.String"));
table.Columns.Add(colFiledBy);

// here you need to inerate through all rows in your dataset or
whatever you get from the database

foreach (DataRow row in ...) {
DataRow[] rows = table.Select("ShortName = '" + row["ShortName"] +
"'");
if (rows.Count 0) {
DataRow r = rows[0];
r["FiledBy"] += ", " + row["FiledBy"];
} else {
DataRow newRow = table.NewRow();
newRow["ShortName"] = row["ShortName"];
newRow["FiledBy"] = row["FiledBy"];
table.Rows.Add(newRow);
}
}

grdRegister.DataSource = table;
grdRegister.DataBind();

Alexander Kleshchevnikov
www.klalex.com

"""se****@gmail.com ÐÉÓÁÌ(Á):
"""
Hi,

I need to merge the rows in the datagrid based on the condition.Please
let me know how can i do that.Here is the scenario:

Present View:

Short name Filed by
A P
A Q
A R
B S
B T
B U
C V
C W

But i need to display like this:
Short Name Filed By
A P,Q,R
B S,T,U
C V,W

For that i used itemtemplate in the grid control as below:

<asp:datagrid id="grdRegister" Runat="server"
OnPageIndexChanged="NewPage" Headerstyle-BackColor="#9B9BB4"
Width="100%" HeaderStyle-Font-Bold="True"
HeaderStyle-ForeColor="#000000" HeaderStyle-CssClass="tableheader"
AutoGenerateColumns="False"
Font-Name="verdana">
<AlternatingItemStyle BackColor="#e2e2e2" Font-Name="verdana"
/>
<Columns>
<asp:BoundColumn DataField="Short/Long Entry"
HeaderText="Short/Long Entry" />

<asp:TemplateColumn HeaderText="Filed by">
<ItemTemplate >
<asp:Label runat="server" Text='<%# string.Format( "{0},
{1}",
DataBinder.Eval(Container, "DataItem.Filed By"),
DataBinder.Eval(Container, "DataItem.Short/Long Entry") ) %>'
ID="Label4">
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
Please let me know how can i achieve that.

Thanks,
Vishnu
Nov 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: learner | last post by:
Hi, In a page, i have many links. I have some functions in a global file which is included in all linked pages. I want to have a reference to a window which is to be opened on clicking one link...
2
by: Dimitri | last post by:
PLEASE HELP,I HAVE A DATABSE WITH MULTIPLE RECORDS AS OUTLINED BELOW EMP NO LEVEL NEXTINCREASE WAGETYPE UNIT 1000 1 0 1000 1000 1 0 1002 ...
28
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
0
by: Charles Dido | last post by:
Sir, I am MR.CHARLES ALAMIEYESEIGHA. I am the son of GOVONOUR of BAYELSA STATE IN NIGERIA.Some months ago, this YEAR, my father was arrested in LONDON by the LONDON METHROPOLITAN POLICE for...
17
by: Saps | last post by:
Hi all. Can anyone help me here. I have loads of .sql files and i need a way to call these from my asp page so the user can run them from the browser. Meaning i have a page with a list of all...
3
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from...
4
by: Adrian Parker | last post by:
We've suddenly started getting a problem with a call to clear the contents of a DataTable. This is on a live customer site that's been working fine until yesterday. As far as we know they've not...
5
by: igotyourdotnet | last post by:
I'm creating a web service this is going to return an arraylist of items. When I try and run it Im' getting the following error message: System.InvalidOperationException: There was an error...
4
by: ashasivan | last post by:
Hi, Please help me as soon as possible for the following problem. It is very very urgent. I have an XML file as follows: <?xml version="1.0" standalone="yes"?> <Employee> <em...
1
by: psantosh12 | last post by:
Hello Frnds Please need help to resolve error.......... it is very very urgent........ The error is Runtime Error Description: An application error occurred on the server. The current custom...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.