Hi,
Code attached but the line that gives me an error is
MyDataGrid.Columns(2).Visible = False
It actually gives me an error for any value instead of 2 even when 9 bound
columns of data exist. How do i hide a column? Thanks.
MyConnection = New
SqlConnection("server=(local);database=pubs;Truste d_Connection=yes")
MyCommand = New SqlDataAdapter("select * from Authors",
MyConnection)
DS = New DataSet
MyCommand.Fill(DS, "Authors")
MyDataGrid.DataSource = DS.Tables("Authors").DefaultView
MyDataGrid.DataBind()
MyDataGrid.BackColor = Color.White
MyDataGrid.BorderColor = Color.Violet
MyDataGrid.BorderStyle = BorderStyle.Dotted
MyDataGrid.ToolTip = "JBs table"
'!!!!!!Error line - out of range althought there are 9 columns.
MyDataGrid.Columns(2).Visible = False
<ASP:DataGrid id="MyDataGrid" runat="server" Width="700"
BackColor="#ccccff" BorderColor="black"
ShowFooter="false" CellPadding="3" CellSpacing="3" Font-Name="Verdana"
Font-Size="8pt" HeaderStyle-BackColor="#aaaadd"
EnableViewState="false" /> 15 3647
Since you know that you want to hide Col.2 why dont you set it to
visible=false during the design time?
Hth...
R. Thomas
"John Blair" wrote: Hi,
Code attached but the line that gives me an error is MyDataGrid.Columns(2).Visible = False It actually gives me an error for any value instead of 2 even when 9 bound columns of data exist. How do i hide a column? Thanks.
MyConnection = New SqlConnection("server=(local);database=pubs;Truste d_Connection=yes") MyCommand = New SqlDataAdapter("select * from Authors", MyConnection)
DS = New DataSet MyCommand.Fill(DS, "Authors")
MyDataGrid.DataSource = DS.Tables("Authors").DefaultView MyDataGrid.DataBind() MyDataGrid.BackColor = Color.White MyDataGrid.BorderColor = Color.Violet MyDataGrid.BorderStyle = BorderStyle.Dotted MyDataGrid.ToolTip = "JBs table"
'!!!!!!Error line - out of range althought there are 9 columns. MyDataGrid.Columns(2).Visible = False
<ASP:DataGrid id="MyDataGrid" runat="server" Width="700" BackColor="#ccccff" BorderColor="black" ShowFooter="false" CellPadding="3" CellSpacing="3" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" EnableViewState="false" />
Thanks for feedback....but as its databound the column does not exist at
design time only run-time! Therefore im looking for a run-time way of hiding
the data (i want to associate data with the row but not show it to the user)
...in case you were going to just say remove it from the SQL statement!
Thanks.
"R. Thomas, aka Xtreme.Net" <NoSpam(Xt**********@hotmail.com.NoSpam> wrote
in message news:EF**********************************@microsof t.com... Since you know that you want to hide Col.2 why dont you set it to visible=false during the design time? Hth... R. Thomas
"John Blair" wrote:
Hi,
Code attached but the line that gives me an error is MyDataGrid.Columns(2).Visible = False It actually gives me an error for any value instead of 2 even when 9 bound columns of data exist. How do i hide a column? Thanks.
MyConnection = New SqlConnection("server=(local);database=pubs;Truste d_Connection=yes") MyCommand = New SqlDataAdapter("select * from Authors", MyConnection)
DS = New DataSet MyCommand.Fill(DS, "Authors")
MyDataGrid.DataSource = DS.Tables("Authors").DefaultView MyDataGrid.DataBind() MyDataGrid.BackColor = Color.White MyDataGrid.BorderColor = Color.Violet MyDataGrid.BorderStyle = BorderStyle.Dotted MyDataGrid.ToolTip = "JBs table"
'!!!!!!Error line - out of range althought there are 9 columns. MyDataGrid.Columns(2).Visible = False
<ASP:DataGrid id="MyDataGrid" runat="server" Width="700" BackColor="#ccccff" BorderColor="black" ShowFooter="false" CellPadding="3" CellSpacing="3" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" EnableViewState="false" />
Ofcource, No one will ever suggest to remove the col from SQL..
But here is something you can try..
Check if there is actually some data in the datagrid before you try to hide
the col.
Lemme know if there is any data is the datagrid when u are trying to hide
the col.
Hth..
R. Thomas
"John Blair" wrote: Thanks for feedback....but as its databound the column does not exist at design time only run-time! Therefore im looking for a run-time way of hiding the data (i want to associate data with the row but not show it to the user) ...in case you were going to just say remove it from the SQL statement! Thanks.
"R. Thomas, aka Xtreme.Net" <NoSpam(Xt**********@hotmail.com.NoSpam> wrote in message news:EF**********************************@microsof t.com... Since you know that you want to hide Col.2 why dont you set it to visible=false during the design time? Hth... R. Thomas
"John Blair" wrote:
Hi,
Code attached but the line that gives me an error is MyDataGrid.Columns(2).Visible = False It actually gives me an error for any value instead of 2 even when 9 bound columns of data exist. How do i hide a column? Thanks.
MyConnection = New SqlConnection("server=(local);database=pubs;Truste d_Connection=yes") MyCommand = New SqlDataAdapter("select * from Authors", MyConnection)
DS = New DataSet MyCommand.Fill(DS, "Authors")
MyDataGrid.DataSource = DS.Tables("Authors").DefaultView MyDataGrid.DataBind() MyDataGrid.BackColor = Color.White MyDataGrid.BorderColor = Color.Violet MyDataGrid.BorderStyle = BorderStyle.Dotted MyDataGrid.ToolTip = "JBs table"
'!!!!!!Error line - out of range althought there are 9 columns. MyDataGrid.Columns(2).Visible = False
<ASP:DataGrid id="MyDataGrid" runat="server" Width="700" BackColor="#ccccff" BorderColor="black" ShowFooter="false" CellPadding="3" CellSpacing="3" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" EnableViewState="false" />
This is the first time to give solutions. If any mistakes pls execuse
me.
First, what are the rows u want ot hide,
Using DataTable.Select('condition','order by columns');
Or
Using DataView.Filter() methods you can hide the values.
Thanks for the reply - but i am trying to hide a column not a row.
I want to show ALL rows but only certain columns.
It appears that the nine databount columns dont appear in the
datagrid.columns.count - it shows as 0 instead of 9.
Thanks.
"Ramesh" <na**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com... This is the first time to give solutions. If any mistakes pls execuse me.
First, what are the rows u want ot hide, Using DataTable.Select('condition','order by columns'); Or Using DataView.Filter() methods you can hide the values.
Hi,
There are 23 rows of data in 9 columns but the columns.count is still
showing as 0 - it doesnt seem to synchronsize with the databound data!
thanks.
"R. Thomas, aka Xtreme.Net" <NoSpam(Xt**********@hotmail.com.NoSpam> wrote
in message news:24**********************************@microsof t.com... Ofcource, No one will ever suggest to remove the col from SQL.. But here is something you can try.. Check if there is actually some data in the datagrid before you try to hide the col. Lemme know if there is any data is the datagrid when u are trying to hide the col. Hth.. R. Thomas
"John Blair" wrote:
Thanks for feedback....but as its databound the column does not exist at design time only run-time! Therefore im looking for a run-time way of hiding the data (i want to associate data with the row but not show it to the user) ...in case you were going to just say remove it from the SQL statement! Thanks.
"R. Thomas, aka Xtreme.Net" <NoSpam(Xt**********@hotmail.com.NoSpam> wrote in message news:EF**********************************@microsof t.com... > Since you know that you want to hide Col.2 why dont you set it to > visible=false during the design time? > Hth... > R. Thomas > > > "John Blair" wrote: > >> Hi, >> >> Code attached but the line that gives me an error is >> MyDataGrid.Columns(2).Visible = False >> It actually gives me an error for any value instead of 2 even when 9 >> bound >> columns of data exist. How do i hide a column? Thanks. >> >> MyConnection = New >> SqlConnection("server=(local);database=pubs;Truste d_Connection=yes") >> MyCommand = New SqlDataAdapter("select * from Authors", >> MyConnection) >> >> DS = New DataSet >> MyCommand.Fill(DS, "Authors") >> >> >> MyDataGrid.DataSource = DS.Tables("Authors").DefaultView >> MyDataGrid.DataBind() >> MyDataGrid.BackColor = Color.White >> MyDataGrid.BorderColor = Color.Violet >> MyDataGrid.BorderStyle = BorderStyle.Dotted >> MyDataGrid.ToolTip = "JBs table" >> >> '!!!!!!Error line - out of range althought there are 9 >> columns. >> MyDataGrid.Columns(2).Visible = False >> >> >> <ASP:DataGrid id="MyDataGrid" runat="server" Width="700" >> BackColor="#ccccff" BorderColor="black" >> ShowFooter="false" CellPadding="3" CellSpacing="3" >> Font-Name="Verdana" >> Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" >> EnableViewState="false" /> >> >> >> >> >>
Hi Ramesh, when u user Select or Filter, what you are doin is that you are
seperating the values that you need.
But I believe the purpose of John is to use the hidden col for ID purposes
etc..
"Ramesh" wrote: This is the first time to give solutions. If any mistakes pls execuse me.
First, what are the rows u want ot hide, Using DataTable.Select('condition','order by columns'); Or Using DataView.Filter() methods you can hide the values.
See, now that is exactly what I was asking, if you have something in the
datagrid to start with.
Now that you know that there is nothin in the datagrid, the error must have
become obvious - there are no cols that you can hide.
I hope now you have got the root cause of ur prob and can rectify it easily
P.S: If this thread was usefull to you, pls click 'Yes' on the top.
Hth..
R. Thomas
"John Blair" wrote: Thanks for the reply - but i am trying to hide a column not a row. I want to show ALL rows but only certain columns. It appears that the nine databount columns dont appear in the datagrid.columns.count - it shows as 0 instead of 9.
Thanks.
"Ramesh" <na**********@gmail.com> wrote in message news:11**********************@z14g2000cwz.googlegr oups.com... This is the first time to give solutions. If any mistakes pls execuse me.
First, what are the rows u want ot hide, Using DataTable.Select('condition','order by columns'); Or Using DataView.Filter() methods you can hide the values.
Tnanks for the feedback but sorry - i dont believe you understand my
problem.
The grid has no rows or columns initially because it is a databound one.
Once bound via SQL statement there are 23 rows 9 columns.
After data binding i.e. MyDataGrid.DataBind() i want to hide one of those
columns
- i cant do it by making e.g. column(2).visible = false because
..columns.count is still 0.
Hope this is clearer....thanks anyway.
"R. Thomas, aka Xtreme.Net" <NoSpam(Xt**********@hotmail.com.NoSpam> wrote
in message news:15**********************************@microsof t.com... See, now that is exactly what I was asking, if you have something in the datagrid to start with. Now that you know that there is nothin in the datagrid, the error must have become obvious - there are no cols that you can hide. I hope now you have got the root cause of ur prob and can rectify it easily P.S: If this thread was usefull to you, pls click 'Yes' on the top. Hth.. R. Thomas "John Blair" wrote:
Thanks for the reply - but i am trying to hide a column not a row. I want to show ALL rows but only certain columns. It appears that the nine databount columns dont appear in the datagrid.columns.count - it shows as 0 instead of 9.
Thanks.
"Ramesh" <na**********@gmail.com> wrote in message news:11**********************@z14g2000cwz.googlegr oups.com... > This is the first time to give solutions. If any mistakes pls execuse > me. > > First, what are the rows u want ot hide, > Using DataTable.Select('condition','order by columns'); > Or > Using DataView.Filter() methods you can hide the values. >
The reason for the error you are getting is that autogenerated columns are
not getting to Columns collection. You have 2 ways of solving the problem.
1. Add the columns in design time. Then you will find them in Columns
collection.
2. Even if the columns are autogenerated, you can handle ItemCreated event
in code-behind. Items corresponds to rows. In the event handler you can
access the cells of the rows you want to hide and make them invisible either
by setting Visible property or by setting a css style rule display:none.
Eliyahu
"John Blair" <jo********@hotmail.com> wrote in message
news:SH*************@newsfe1-gui.ntli.net... Hi,
Code attached but the line that gives me an error is MyDataGrid.Columns(2).Visible = False It actually gives me an error for any value instead of 2 even when 9 bound columns of data exist. How do i hide a column? Thanks.
MyConnection = New SqlConnection("server=(local);database=pubs;Truste d_Connection=yes") MyCommand = New SqlDataAdapter("select * from Authors", MyConnection)
DS = New DataSet MyCommand.Fill(DS, "Authors")
MyDataGrid.DataSource = DS.Tables("Authors").DefaultView MyDataGrid.DataBind() MyDataGrid.BackColor = Color.White MyDataGrid.BorderColor = Color.Violet MyDataGrid.BorderStyle = BorderStyle.Dotted MyDataGrid.ToolTip = "JBs table"
'!!!!!!Error line - out of range althought there are 9 columns. MyDataGrid.Columns(2).Visible = False
<ASP:DataGrid id="MyDataGrid" runat="server" Width="700" BackColor="#ccccff" BorderColor="black" ShowFooter="false" CellPadding="3" CellSpacing="3" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" EnableViewState="false" />
Very impressed thanks a lot - i chose to use your second method using the
itemcreated event.
Code used to hide the first column for the others who posted to this
subject.
<ASP:DATAGRID id="MyDataGrid" runat="server" OnItemCreated="Item_Created"
....
</ASP:DATAGRID>
Sub Item_Created(sender As Object, e As DataGridItemEventArgs)
e.item.cells(0).visible = false
End Sub 'Item_Created
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... The reason for the error you are getting is that autogenerated columns are not getting to Columns collection. You have 2 ways of solving the problem.
1. Add the columns in design time. Then you will find them in Columns collection.
2. Even if the columns are autogenerated, you can handle ItemCreated event in code-behind. Items corresponds to rows. In the event handler you can access the cells of the rows you want to hide and make them invisible either by setting Visible property or by setting a css style rule display:none.
Eliyahu
"John Blair" <jo********@hotmail.com> wrote in message news:SH*************@newsfe1-gui.ntli.net... Hi,
Code attached but the line that gives me an error is MyDataGrid.Columns(2).Visible = False It actually gives me an error for any value instead of 2 even when 9 bound columns of data exist. How do i hide a column? Thanks.
MyConnection = New SqlConnection("server=(local);database=pubs;Truste d_Connection=yes") MyCommand = New SqlDataAdapter("select * from Authors", MyConnection)
DS = New DataSet MyCommand.Fill(DS, "Authors")
MyDataGrid.DataSource = DS.Tables("Authors").DefaultView MyDataGrid.DataBind() MyDataGrid.BackColor = Color.White MyDataGrid.BorderColor = Color.Violet MyDataGrid.BorderStyle = BorderStyle.Dotted MyDataGrid.ToolTip = "JBs table"
'!!!!!!Error line - out of range althought there are 9 columns. MyDataGrid.Columns(2).Visible = False
<ASP:DataGrid id="MyDataGrid" runat="server" Width="700" BackColor="#ccccff" BorderColor="black" ShowFooter="false" CellPadding="3" CellSpacing="3" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" EnableViewState="false" />
John:
I believe the column count is always 0 if the grid is set to
autogenerate columns...
--
Scott http://www.OdeToCode.com/blogs/scott/
On Mon, 27 Dec 2004 11:58:22 GMT, "John Blair"
<jo********@hotmail.com> wrote: Hi,
There are 23 rows of data in 9 columns but the columns.count is still showing as 0 - it doesnt seem to synchronsize with the databound data!
thanks.
unless you add some columns manually
Eliyahu
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:c3********************************@4ax.com... John:
I believe the column count is always 0 if the grid is set to autogenerate columns...
-- Scott http://www.OdeToCode.com/blogs/scott/
On Mon, 27 Dec 2004 11:58:22 GMT, "John Blair" <jo********@hotmail.com> wrote:
Hi,
There are 23 rows of data in 9 columns but the columns.count is still showing as 0 - it doesnt seem to synchronsize with the databound data!
thanks.
hi,
The solution is simple go to itembound event and put this line
e.item.cells(0).visible = false
It is advisable to make visiblity and stuff in Item databound event
If you r using .net IDE
The second option is to go to the property builder and set the visible check
box of column in columns
happy coding
Regards,
Mehta Rahul
"John Blair" wrote: Very impressed thanks a lot - i chose to use your second method using the itemcreated event. Code used to hide the first column for the others who posted to this subject.
<ASP:DATAGRID id="MyDataGrid" runat="server" OnItemCreated="Item_Created" .... </ASP:DATAGRID>
Sub Item_Created(sender As Object, e As DataGridItemEventArgs)
e.item.cells(0).visible = false
End Sub 'Item_Created "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... The reason for the error you are getting is that autogenerated columns are not getting to Columns collection. You have 2 ways of solving the problem.
1. Add the columns in design time. Then you will find them in Columns collection.
2. Even if the columns are autogenerated, you can handle ItemCreated event in code-behind. Items corresponds to rows. In the event handler you can access the cells of the rows you want to hide and make them invisible either by setting Visible property or by setting a css style rule display:none.
Eliyahu
"John Blair" <jo********@hotmail.com> wrote in message news:SH*************@newsfe1-gui.ntli.net... Hi,
Code attached but the line that gives me an error is MyDataGrid.Columns(2).Visible = False It actually gives me an error for any value instead of 2 even when 9 bound columns of data exist. How do i hide a column? Thanks.
MyConnection = New SqlConnection("server=(local);database=pubs;Truste d_Connection=yes") MyCommand = New SqlDataAdapter("select * from Authors", MyConnection)
DS = New DataSet MyCommand.Fill(DS, "Authors")
MyDataGrid.DataSource = DS.Tables("Authors").DefaultView MyDataGrid.DataBind() MyDataGrid.BackColor = Color.White MyDataGrid.BorderColor = Color.Violet MyDataGrid.BorderStyle = BorderStyle.Dotted MyDataGrid.ToolTip = "JBs table"
'!!!!!!Error line - out of range althought there are 9 columns. MyDataGrid.Columns(2).Visible = False
<ASP:DataGrid id="MyDataGrid" runat="server" Width="700" BackColor="#ccccff" BorderColor="black" ShowFooter="false" CellPadding="3" CellSpacing="3" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" EnableViewState="false" />
This is the first time to give solutions. If any mistakes pls execuse
me.
First, what are the rows u want ot hide,
Using DataTable.Select('condition','order by columns');
Or
Using DataView.Filter() methods you can hide the values. This discussion thread is closed Replies have been disabled for this discussion. Similar topics
1 post
views
Thread by Fresh Air Rider |
last post: by
|
4 posts
views
Thread by z. f. |
last post: by
|
1 post
views
Thread by roni |
last post: by
|
4 posts
views
Thread by Satya |
last post: by
|
reply
views
Thread by John Smith |
last post: by
|
reply
views
Thread by John Smith |
last post: by
|
2 posts
views
Thread by John Smith |
last post: by
|
2 posts
views
Thread by John Smith |
last post: by
| | | | | | | | | | | |