you can use PIVOT in sql server query and you can fetch your output from Sql Server and disply on Grid
About Pivot :-
Pivot tables display data in tabular form. The pivot table formatting is not different than a tabular report formatting.
But the table columns are formed by the report data itself.
I guess you are having no problem getting the data and binding it to the gridview but the only part is that you want the gridview to be grouped by the UserID,
Highflame
Member
69 Points
53 Posts
How to Merge First Column Rows of Similar Data In GridView usign C#/Sql 2008
Jan 03, 2012 11:03 AM|LINK
Hello Friend,
Iam New to the .NET...
Iam getting this type of UI as iam binding the Grid from SQlServer...
Eg: UserID | Type | Date | Status
001 Enquiry 01/12/2011 Closed
001 Complaint 02/12/2011 InProgress
001 Complaint 03/12/2011 Open
002 Enquiry 04/12/2011 Closed
003 Suggestion 04/12/2011 Closed
But i need this type of UI :
UserID | Type | Date | Status
Enquiry 01/12/2011 Closed
001 Complaint 02/12/2011 InProgress
Complaint 03/12/2011 Open
002 Enquiry 04/12/2011 Closed
003 Suggestion 04/12/2011 Closed
Thanks in Advance
Sujeet Bhujb...
Member
306 Points
81 Posts
Re: How to Merge First Column Rows of Similar Data In GridView usign C#/Sql 2008
Jan 03, 2012 11:17 AM|LINK
Hi,
you can use PIVOT in sql server query and you can fetch your output from Sql Server and disply on Grid
About Pivot :-
Pivot tables display data in tabular form. The pivot table formatting is not different than a tabular report formatting.
But the table columns are formed by the report data itself.
Sujeet Bhujbal
Sujeet Bhujbal's Blog
--------------------------------------------------------
If the post is useful don't forget to MARK as Answer
Highflame
Member
69 Points
53 Posts
Re: How to Merge First Column Rows of Similar Data In GridView usign C#/Sql 2008
Jan 03, 2012 11:27 AM|LINK
Sujeet can u provide some example.
Arunmhn
Participant
1876 Points
347 Posts
Re: How to Merge First Column Rows of Similar Data In GridView usign C#/Sql 2008
Jan 03, 2012 11:32 AM|LINK
I guess you are having no problem getting the data and binding it to the gridview but the only part is that you want the gridview to be grouped by the UserID,
this cant be done in the GridView directly however there are workarounds to achieve this, you can find some samples here https://forums.asp.net/t/1701667.aspx/1?How+to+display+gridview+with+2+columns+in+group+by
Sujeet Bhujb...
Member
306 Points
81 Posts
Re: How to Merge First Column Rows of Similar Data In GridView usign C#/Sql 2008
Jan 04, 2012 03:58 AM|LINK
Hi friend,
I have another solution for same . you can use row databound of gridview for that
I have done some sample aspx page.
Below is the source code
Aspx page
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
BorderStyle="None" BorderWidth="1px" CellPadding="4"
GridLines="Horizontal" ForeColor="Black"
Height="119px" DataSourceID="SqlDataSource1"
OnDataBound="GridView1_DataBound1">
<Columns>
<asp:BoundField DataField="Country"
HeaderText="Country"
SortExpression="Country" />
<asp:BoundField DataField="State"
HeaderText="State"
SortExpression="State" />
<asp:BoundField DataField="City"
HeaderText="City"
SortExpression="City" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Country], [State], [City]
FROM [Details] ORDER BY [State]">
</asp:SqlDataSource>
code behind
protected void GridView1_DataBound1(object sender, EventArgs e)
{
for (int rowIndex = GridView1.Rows.Count - 2;
rowIndex >= 0; rowIndex--)
{
GridViewRow gvRow = GridView1.Rows[rowIndex];
GridViewRow gvPreviousRow = GridView1.Rows[rowIndex + 1];
for (int cellCount = 0; cellCount < gvRow.Cells.Count;
cellCount++)
{
if (gvRow.Cells[cellCount].Text ==
gvPreviousRow.Cells[cellCount].Text)
{
if (gvPreviousRow.Cells[cellCount].RowSpan < 2)
{
gvRow.Cells[cellCount].RowSpan = 2;
}
else
{
gvRow.Cells[cellCount].RowSpan =
gvPreviousRow.Cells[cellCount].RowSpan + 1;
}
gvPreviousRow.Cells[cellCount].Visible = false;
}
}
}
}
Please mark as answer for my post
Regards
Sujeet
Sujeet Bhujbal
Sujeet Bhujbal's Blog
--------------------------------------------------------
If the post is useful don't forget to MARK as Answer
jennyortem
Member
306 Points
97 Posts
Re: How to Merge First Column Rows of Similar Data In GridView usign C#/Sql 2008
Jan 04, 2012 04:09 AM|LINK
Hello,
Please specify where you want to display the userid?
where the status i closed or Inprogress? please specify.
Highflame
Member
69 Points
53 Posts
Re: How to Merge First Column Rows of Similar Data In GridView usign C#/Sql 2008
Jan 04, 2012 04:52 AM|LINK
Thanks for reply Friends.
Whatever be the status if userID is same it should merge, this is my requirement.
Highflame
Member
69 Points
53 Posts
Re: How to Merge First Column Rows of Similar Data In GridView usign C#/Sql 2008
Jan 04, 2012 04:53 AM|LINK
Thanks Sujeet i tried ur code snippet and it works fine...
Thanks a lot Friends.
salman beher...
All-Star
30579 Points
5852 Posts
Re: How to Merge First Column Rows of Similar Data In GridView usign C#/Sql 2008
Jan 04, 2012 05:02 AM|LINK
Hi,
here what you need...
http://csharpdotnetfreak.blogspot.com/2009/07/merge-gridview-cells-columns-aspnet.html
http://weblogs.asp.net/brijmohan/archive/2011/09/03/rows-and-columns-merging-in-asp-net-gridview-control.aspx
Thanks...
Sincerely,
Salman
munirah-mali...
Member
83 Points
111 Posts
Re: How to Merge First Column Rows of Similar Data In GridView usign C#/Sql 2008
May 25, 2012 05:37 AM|LINK
how to merge just column 1 only. please help.