如何使< ASP:DataGrid列在其数据绑定时不可见? [英] How do a make an <ASP:DataGrid column invisible when its data bound?

查看:76
本文介绍了如何使< ASP:DataGrid列在其数据绑定时不可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




附加代码,但是给我一个错误的行是

MyDataGrid.Columns(2).Visible = False

它实际上给了我一个错误,而不是2,即使存在9个绑定的b / b $ b列数据。我如何隐藏列?谢谢。


MyConnection =新

SqlConnection(" server =(local); database = pubs; Truste d_Connection = yes")

MyCommand = New SqlDataAdapter(" select * from Authors",

MyConnection)


DS =新数据集

MyCommand.Fill(DS,作者)

MyDataGrid.DataSource = DS.Tables(" Authors")。DefaultView

MyDataGrid.DataBind()

MyDataGrid.BackColor = Color.White

MyDataGrid.BorderColor = Color.Violet

MyDataGrid.BorderStyle = BorderStyle.Dotted

MyDataGrid.ToolTip =" JBs table"


''!!!!!!错误行 - 超出范围,但有9列。

MyDataGrid .Columns(2).Visible = False

< ASP:DataGrid id =" MyDataGrid" RUNAT = QUOT;服务器" Width =" 700"

BackColor =" #ccccff" BorderColor =" black"

ShowFooter =" false" CELLPADDING = QUOT; 3英寸CELLSPACING = QUOT; 3英寸Font-Name =" Verdana"

字体大小=" 8pt" HeaderStyle-BackColor =" #aaaadd"

EnableViewState =" false" />

解决方案

既然你知道要隐藏Col.2为什么不把它设置为

在设计时间可见=假?

Hth ...

R. Thomas

" John Blair" ;写道:



代码附加但是给我一个错误的行是
MyDataGrid.Columns(2).Visible = False
它实际上给了我一个错误,而不是2,即使存在9个绑定的数据列。我如何隐藏列?谢谢。

MyConnection =新的
SqlConnection(" server =(local); database = pubs; Truste d_Connection = yes")
MyCommand = New SqlDataAdapter(" select *来自作者",
MyConnection)

DS =新数据集
MyCommand.Fill(DS,作者)

MyDataGrid.DataSource = DS .Tables(" Authors")。DefaultView
MyDataGrid.DataBind()
MyDataGrid.BackColor = Color.White
MyDataGrid.BorderColor = Color.Violet
MyDataGrid.BorderStyle = BorderStyle .Dotted
MyDataGrid.ToolTip =" JBs table"

''!!!!!!错误行 - 超出范围,但有9列。
MyDataGrid.Columns (2).Visible = False

< ASP:DataGrid id =" MyDataGrid" RUNAT = QUOT;服务器" Width =" 700"
BackColor =" #ccccff" BorderColor =" black"
ShowFooter =" false" CELLPADDING = QUOT; 3英寸CELLSPACING = QUOT; 3英寸Font-Name =" Verdana"
Font-Size =" 8pt" HeaderStyle-BackColor =" #aaaadd"
EnableViewState =" false" />



感谢您提供反馈....但由于其数据绑定,该列不存在于

设计时间只限运行时间!因此我正在寻找一种隐藏数据的运行时方式(我希望将数据与行关联但不向用户显示)

... in你只想说从SQL语句中删除它!

谢谢。


" R. Thomas,又名Xtreme.Net < NoSpam(Xt ********** @ hotmail.com.NoSpam>在消息新闻中写道

:EF ************** ******************** @ microsof t.com ...

因为你知道你想要隐藏Col.2为什么不要你在设计时将它设置为
visible = false?
R. Thomas

" John Blair"写道:
< blockquote class =post_quotes>

代码附加但是给我一个错误的行是
MyDataGrid.Columns(2).Visible = False
它实际上给了我即使存在数据列,也存在任何值而不是2的错误。如何隐藏列?谢谢。

MyConnection =新的
SqlConnection (" server =(local); database = pubs; Truste d_Connection = yes")
MyCommand = New SqlDataAdapter(" select * from Authors",
MyConnection)

DS =新数据集
MyCommand.Fill(DS,作者)

MyDataGrid.Da taSource = DS.Tables(" Authors")。DefaultView
MyDataGrid.DataBind()
MyDataGrid.BackColor = Color.White
MyDataGrid.BorderColor = Color.Violet
MyDataGrid。 BorderStyle = BorderStyle.Dotted
MyDataGrid.ToolTip =" JBs table"

''!!!!!!错误行 - 超出范围,但有9列。
MyDataGrid.Columns(2).Visible = False

< ASP:DataGrid id =" MyDataGrid" RUNAT = QUOT;服务器" Width =" 700"
BackColor =" #ccccff" BorderColor =" black"
ShowFooter =" false" CELLPADDING = QUOT; 3英寸CELLSPACING = QUOT; 3英寸Font-Name =" Verdana"
Font-Size =" 8pt" HeaderStyle-BackColor =" #aaaadd"
EnableViewState =" false" />



Ofcource,没有人会建议从SQL中删除col ..

但是这里有你可以试试的东西..

在你试图隐藏之前检查数据网格中是否有一些数据

col。

当你试图隐藏时,Lemme知道数据网格是否有任何数据

col。

Hth ..

R. Thomas


" John Blair"写道:

感谢您的反馈....但由于它的数据绑定列在
设计时不存在仅运行时!因此,我正在寻找一种隐藏数据的运行时方式(我希望将数据与行关联但不向用户显示)
...以防万一你只想说删除它来自SQL语句!
谢谢。

R。 Thomas,又名Xtreme.Net < NoSpam(Xt ********** @ hotmail.com.NoSpam>在消息新闻中写道
:EF ****************** **************** @ microsof t.com ...

因为你知道你想要隐藏Col.2为什么不把它设置为
在设计时间内可见=假?
R. Thomas

" John Blair"写道:



代码附加但是给我一个错误的行是
MyDataGrid.Columns(2).Visible = False
它实际上给了我一个错误即使存在9列数据,也不是2。如何隐藏列?谢谢。

MyConnection =新的
SqlConnection("服务器) =(local); database = pubs; Truste d_Connection = yes")
MyCommand = New SqlDataAdapter(" select * from Authors",
MyConnection)

DS = New DataSet
MyCommand.Fill(DS,作者)

MyDataGrid.DataSou rce = DS.Tables(" Authors")。DefaultView
MyDataGrid.DataBind()
MyDataGrid.BackColor = Color.White
MyDataGrid.BorderColor = Color.Violet
MyDataGrid。 BorderStyle = BorderStyle.Dotted
MyDataGrid.ToolTip =" JBs table"

''!!!!!!错误行 - 超出范围,但有9列。
MyDataGrid.Columns(2).Visible = False

< ASP:DataGrid id =" MyDataGrid" RUNAT = QUOT;服务器" Width =" 700"
BackColor =" #ccccff" BorderColor =" black"
ShowFooter =" false" CELLPADDING = QUOT; 3英寸CELLSPACING = QUOT; 3英寸Font-Name =" Verdana"
Font-Size =" 8pt" HeaderStyle-BackColor =" #aaaadd"
EnableViewState =" false" />




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" />


解决方案

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" />




这篇关于如何使&lt; ASP:DataGrid列在其数据绑定时不可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆