I confirmed the app run this dglist_initializeRow event before bind the data into the datagrid.
Protected Sub dgList_InitializeRow(sender As Object, e As Infragistics.Web.UI.GridControls.RowEventArgs) Handles dgList.InitializeRow
e.Row.Items.FindItemByKey("SNIndex").Column.Hidden = True e.Row.Items.FindItemByKey("Format").Column.Hidden = True e.Row.Items.FindItemByKey("FormatRef").Column.Hidden = True e.Row.Items.FindItemByKey("SPONoRef").Column.Hidden = True
End Sub
the data extract from database and convert into datatable before bind to datagrid
dgLis.t.DataSource = dsSNFormat.Tables(0)
dgList.DataBind()
after binding the data, I call this function to hide the column that I want, but unfortunately, only the header and width take effect from this function. My column still not hiding as I expect.
Public Sub showhidecolumn()
For a As Integer = 0 To dgList.Rows.Count - 1 dgList.Rows(a).Items(0).Column.Hidden = True dgList.Rows(a).Items(0).Column.Width = 0 dgList.Rows(a).Items(0).Column.Header.Text = "" dgList.Rows(a).Items(1).Column.Hidden = True dgList.Rows(a).Items(1).Column.Width = 0 dgList.Rows(a).Items(1).Column.Header.Text = "" dgList.Rows(a).Items(5).Column.Hidden = True dgList.Rows(a).Items(5).Column.Width = 0 dgList.Rows(a).Items(5).Column.Header.Text = "" dgList.Rows(a).Items(11).Column.Hidden = True dgList.Rows(a).Items(11).Column.Width = 0 dgList.Rows(a).Items(11).Column.Header.Text = "" Next End Sub
Any suggestion? by the way, my column type is BoundDataField, is it got a special trick to hide that column's type? Please help I'm quite stuck right now.
Thanks in advance.
Hello Zuliana,
In order to hide a column in code behind, what you could do is accessing the column in the Initialize server-side event of the grid and set its hidden property to true. The only difference from your code is that if you are using the InitializeRow event you would be setting this property n number of times, depending on the number of rows you have in the grid, while if you are using the Initialize event the property would be assigned only once. This could be achieved with the following code:
Protected Sub WebDataGrid1_Init(ByVal sender As Object, ByVal e As EventArgs) Me.WebDataGrid1.Columns(2).Hidden = True 'you can also use the line below if you want to access the column by index instead of key ' Me.WebDataGrid1.Columns.FromKey("Date").Hidden = True End Sub
Please let me know if you have any questions.
Regards, Ivan Kitanov
Dear Customer,Thank you for contacting Infragistics Developer Support.
We are afraid to say that we now have many inquiries in queue. We are making efforts to take care of them in order of arrival, but it might take some more time until we can start the investigation about this support case.
Thank you in advance for your understanding.