Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 14th, 2005, 08:39 AM
Authorized User
 
Join Date: Nov 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default Column Order

I have a simple datagrid that is databound to an xml file. Unfortunately I do not have the ability to rearrange the order of the xml file, but I need to change the order of the columns in the datagrid. Can someone show me how to change the order of the columns after a databind()?

Thanks,
Levi

 
Old July 14th, 2005, 03:42 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Right click on your grid and choose property builder
Choose columns on the left of the window
UNCheck create columns automatically at runtime
Then select the columns you want in the order you want.

 
Old August 1st, 2005, 10:49 AM
Authorized User
 
Join Date: Nov 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The problem is that my dataset is being built in the Page_Load, and so the dataset is not accessible like that. I need to be able to change the order of the columns programmatically. Any more help PLEASE?

 
Old August 1st, 2005, 12:30 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

OK, then do your select in the order you want. Select <col>, <col> ..etc... then your datagrid will show the order of the select statement

 
Old August 1st, 2005, 12:40 PM
Authorized User
 
Join Date: Nov 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here, this might help you understand a little better. I'm not very good at describing things.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        Dim objData1 As New DataSet
        objData1.ReadXml(Server.MapPath("xml/fc.xml"))
        Me.FeederCattleGrid.DataSource = objData1
        Me.FeederCattleGrid.DataBind()
        Me.FeederCattleGrid.Columns(0).Width = New Unit("65px")
        Me.FeederCattleGrid.Columns(0).CellStyle.Horizonta lAlign = HorizontalAlign.Right
        Me.FeederCattleGrid.Columns(1).Width = New Unit("35px")
        Me.FeederCattleGrid.Columns(1).CellStyle.Horizonta lAlign = HorizontalAlign.Right
        Me.FeederCattleGrid.Columns(2).Width = New Unit("70px")
        Me.FeederCattleGrid.Columns(2).CellStyle.Horizonta lAlign = HorizontalAlign.Right
        Me.FeederCattleGrid.Columns(3).Width = New Unit("65px")
        Me.FeederCattleGrid.Columns(3).CellStyle.Horizonta lAlign = HorizontalAlign.Right
        Me.FeederCattleGrid.Columns(4).Width = New Unit("70px")
        Me.FeederCattleGrid.Columns(4).CellStyle.Horizonta lAlign = HorizontalAlign.Right
        Me.FeederCattleGrid.Columns(5).Hidden = True
        Me.FeederCattleGrid.Columns(6).Width = New Unit("45px")
        Me.FeederCattleGrid.Columns(6).CellStyle.Horizonta lAlign = HorizontalAlign.Center
End Sub

This is all of the vb.net code behind the page.

 
Old August 1st, 2005, 01:49 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Create a new dataset
   Dim myNewDS As New DataSet
Add a table to it.

Add columns
   myNewDS.Tables(0).Columns.Add(objData1.Tables(0).C olumns("column you want"))
   myNewDS.Tables(0).Columns.Add(objData1.Tables(0).C olumns("column you want"))

... do that for each column in the order ypu want


 
Old August 1st, 2005, 02:22 PM
Authorized User
 
Join Date: Nov 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I must really suck at this!!!

Column 'SYM' already belongs to this DataTable.

That is the error message I get.

 
Old August 1st, 2005, 02:29 PM
Authorized User
 
Join Date: Nov 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is this an aweful way of doing this. Is there a better way to read the contents of an xml file into a datagrid, so that I have more control over it?

 
Old August 1st, 2005, 11:43 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You neeed to each column only once. I don't know of ean easier way using XML. Your hands are pretty much tied because I don't believe there is a way to change the order of the XML file directly.

 
Old August 2nd, 2005, 05:21 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

busher,

Why can you not specify the column order in the grid's markup? If you are loading data from a known XML file then (hopefully) it will have a regular data structor such that you can specify the column layout.

If the data in the XML is correctly formed, you might be able to load the XML data into a data set. Then you could manipulate the table columns to get them in the order you want. But all of this also assumes that you will know ahead of time how the columns are structured. If that's the case, you can just lay out the grid columns and it will be a lot simpler.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Rearrange the column order in a datatable/dataset kiran_q8 ASP.NET 2.0 Basics 6 July 3rd, 2007 12:12 PM
Rearrange the column order in a datatable/dataset kiran_q8 ASP.NET 2.0 Professional 2 May 3rd, 2007 08:46 AM
VBA Column Sort Order and numbers Jack1000 BOOK: Access 2003 VBA Programmer's Reference 1 October 5th, 2006 10:53 PM
ORDER BY a column? gilgalbiblewheel Classic ASP Databases 1 March 30th, 2005 10:37 AM
updating unit_in_stock column after order olambe SQL Server 2000 7 June 7th, 2004 04:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.