|
Subject:
|
Hiding datagrid column give error
|
|
Posted By:
|
annsary
|
Post Date:
|
4/4/2006 9:34:54 PM
|
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.
|
|
Reply By:
|
jbenson001
|
Reply Date:
|
4/6/2006 12:07:58 AM
|
what is the error? and what line does it occur on?
|
|
Reply By:
|
annsary
|
Reply Date:
|
4/6/2006 2:53:23 AM
|
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.
|
|
Reply By:
|
jbenson001
|
Reply Date:
|
4/6/2006 9:12:38 AM
|
ok great
|
|
Reply By:
|
madhusrp
|
Reply Date:
|
4/6/2006 11:57:46 PM
|
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
|
|
Reply By:
|
annsary
|
Reply Date:
|
4/7/2006 3:45:42 AM
|
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
|