Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional 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 April 4th, 2006, 09:34 PM
Authorized User
 
Join Date: Mar 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hiding datagrid column give error

Hi,
I am reposting this under a new topic.

i am facing another new challenge. i am using .net VS2003 with v1.1 framework
instead of using dataset, i used the dataview as the datasource.
gdataGrid.DataSource = ds.Tables(0).defaultview

so that i can do sorting easily. Now i wish to hide one of the column in the datagrid. the data grid has edit and delete column followed by the dataview's column which consist of No, Item, Desc, etc.
I wish to hide the 'No' column. when i specifiy,
gdataGrid.DataSource = ds.Tables(0).defaultview
gdataGrid.DataBind()
gdataGrid.Columns("No").Visible = False

the above statement gives error and when i checked, the gdataGrid.columns().count gives only 2 (the Edit and the Delete columns). somehow, the columns in the dataviews are not being recognised. how to make the datagrid recognize the columns from the dataview?

I tried using the datagridtablestyle, but the datagridtablestyle is also not recognised by the editor.


Thanks.
 
Old April 6th, 2006, 12:07 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

what is the error? and what line does it occur on?
 
Old April 6th, 2006, 02:53 AM
Authorized User
 
Join Date: Mar 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I am able to hide the column now. previously the columns in datagrid is set as template column. i changed it to bound column and gave the field name for each column. :) so now able to hide the column.
Thanks.


 
Old April 6th, 2006, 09:12 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

ok great

 
Old April 6th, 2006, 11:57 PM
Authorized User
 
Join Date: Jan 2006
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hai ansary can u send the line u have used to get the a cloumn in the datadrid with bound column if possible dsend me the code snippet of every change we should make to make a particular column false dynamically

thanks
Madhu

 
Old April 7th, 2006, 03:45 AM
Authorized User
 
Join Date: Mar 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Madhu,
i set the column bound in the property builder of the datagrid. not in the code. i created 6 columns including the column i wish to hide and indicated in the property builder, the data field. i left the data field empty when i created the datagrid assuming the datafield is only for records from the database. since i am using the databind to bind the datatable i created dynamically, later i entered the datafield in the property field and then i am able to hide the column i dynamically.

Private Sub CreateDataSet()

        sSessionTag = "Tag" & Session.SessionID
        sSessionSort = "Sort" & Session.SessionID

        dt = New DataTable(sTblName)
        ds = New DataSet
        Dim col0 As DataColumn = New DataColumn("No", System.Type.GetType("System.Int32"))
        Dim col1 As DataColumn = New DataColumn("Name", System.Type.GetType("System.String"))
        ... created rest of columns


        dt.Columns.Add(col0)
        dt.Columns.Add(col1)
        dt.Columns.Add(col2)
        dt.Columns.Add(col3)
        dt.Columns.Add(col4)
        dt.Columns.Add(col5)

        ds.Tables.Add(dt)
    End Sub

Private Sub BindGrid()
        Dim dtgCol As DataGridColumn
        If Session(sSessionSort) Is Nothing Then
            Session(sSessionSort) = "Name"
            Session(sSessionSortOrder) = " Asc"
        Else
            dsTag.Tables(sTblName).DefaultView.Sort = CType(Session(sSessionSort), String) & CType(Session(sSessionSortOrder), String)
        End If
        dsTag.Tables(sTblName).DefaultView.RowFilter = ""
        gdataGrid.DataSource = dsTag.Tables(sTblName).DefaultView
        gdataGrid.DataBind()
        gdataGrid.Visible = True
        If gdataGrid.Columns().Count > 0 Then
            gdataGrid.Columns(0).Visible = False
        End If
    End Sub

regards,
annsary






Similar Threads
Thread Thread Starter Forum Replies Last Post
hiding / unhiding columns in datagrid drachx General .NET 9 October 18th, 2004 02:37 AM
Hiding datagrid row selection column Ron Howerton VB.NET 2002/2003 Basics 0 September 25th, 2004 09:57 AM
PublishObjects give Error 1004 TimP Excel VBA 1 June 16th, 2004 03:08 AM
DataGrid hyperlink column error burdickdave ASP.NET 1.x and 2.0 Application Design 3 February 26th, 2004 03:41 PM
Hiding and Resizing Column in MSHFlexGrid Dhodie VB How-To 1 September 21st, 2003 10:20 PM





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