User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 427,935 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,962 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 8299 | Replies: 2
Reply
Join Date: Jan 2006
Posts: 14
Reputation: Texpert is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Texpert's Avatar
Texpert Texpert is offline Offline
Newbie Poster

Pivot table in DataGrid

  #1  
Mar 1st, 2006
Hi,

I need help solving this problem.
I have a dataset with four columns col1,col2,col3,col4 and the data could be
col1 col2 col3 col4
=====================================
t1 abc a 1
t1 xyz a 2
t1 mnp b 3
t2 abc 1
t2 kkl 2

I want to create a datagrid which will have, column headings from the col1 data (t1 and t2 as columns) starting from 2nd column in data grid
1st column heading should be blank (like in excel spreadsheet)
and under 1st column in the datagrid, col2 (from source dataset) values should appear as rows
something like this

t1 t2
===========================
abc
xyz
mnp
kkl

that's not it, now remaining two columns col3 and col4 from the source dataset are the attributes of rows, so somehow I need to split each cell under column t1 and t2 and show values of col3 and col4

so far I could get the column headings t1 and t2
by writing separate query for col2 I can even get the first column in datagrid populated but I am clueless how to get two attributes in one cell

any idea ?

thanks in advance
     Dim MySQLString As String

        Dim objParam1 As SqlParameter
        Dim MyConn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("Conn"))
        Dim dest As DataTable


        Try
            Session("Current_PackageId") = PackageNameDDL.SelectedItem.Value

            'MySQLString = "SELECT DISTINCT Component.Description,Song.SongTitle, "
            'MySQLString = MySQLString + " XREFCompSong.ComponentSeq, XREFCompSong.ComponentSide  "
            'MySQLString = MySQLString + " FROM XREFCompSong INNER JOIN"
            'MySQLString = MySQLString + " Song ON XREFCompSong.SongID = Song.PXSongID INNER JOIN"
            'MySQLString = MySQLString + " Component ON XREFCompSong.ComponentID = Component.ComponentID "
            'MySQLString = MySQLString + " WHERE (Component.PackageID  = @vPackageId)"

            MySQLString = "SELECT DISTINCT Component.Description"
            MySQLString = MySQLString + " FROM Component "
            MySQLString = MySQLString + " WHERE (Component.PackageID  = @vPackageId)"

            Dim MySqldataAdapter As SqlDataAdapter = New SqlDataAdapter(MySQLString, MyConn)
            Dim MyDataSet As DataSet = New DataSet

            objParam1 = MySqldataAdapter.SelectCommand.Parameters.Add("@vPackageId", SqlDbType.Int)
            objParam1.Value = PackageNameDDL.SelectedItem.Value

            If MyConn.State = ConnectionState.Closed Then
                MyConn.Open()
            End If

            MySqldataAdapter.Fill(MyDataSet)

            dest = New DataTable("PivotTable")
            dest.Columns.Add("   ")

            Dim r As DataRow

            For Each r In MyDataSet.Tables(0).Rows
                dest.Columns.Add(r(0))
            Next

            DataGrid1.DataSource = dest
            DataGrid1.DataBind()

                       MyConn.Dispose()
            MyConn.Close()
        Catch ex As Exception
                     System.Diagnostics.Trace.WriteLine("[ShowBtnClick] Exception " & ex.Message)
        Finally
            MyConn.Close()
        End Try
Notice that I've commented out first query, because with that query I get error while creating columns that "column t1 is already in the dataset", since t1 repeates in the query result.

AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2008
Posts: 4
Reputation: luciano_sunny is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
luciano_sunny luciano_sunny is offline Offline
Newbie Poster

Re: Pivot table in DataGrid

  #2  
Feb 26th, 2008
Hi there did you get any reply from anywhere for this problem of yours because i am also stuck with almost same kind of thing.
Reply With Quote  
Join Date: Jul 2008
Posts: 1
Reputation: JakeDB is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
JakeDB JakeDB is offline Offline
Newbie Poster

Re: Pivot table in DataGrid

  #3  
Jul 19th, 2008
Sound like you need a real pivot table gird with some customization capabilities. There are a few of them on the market but usually quite pricy. You can try the VIBlend SuperGridView. http://www.viblend.com. Not too expensive and does a great job.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 6:28 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC