如何在没有昂贵的转换的情况下在DataGrid的ItemDateBound中设置控件? [英] How to set controls in a DataGrid's ItemDateBound without a costly conversion?

查看:59
本文介绍了如何在没有昂贵的转换的情况下在DataGrid的ItemDateBound中设置控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想根据某些条件在DataGrid中显示一个Label。因此,我检查DataGrid的ItemDateBound EventHandler中的条件是否为真。不幸的是,转换的性能极其昂贵。有没有人知道如何将标签(TableCell的整个内容)设置为.Visible = False而不将e.Item.Controls(2)转换为System.Web.UI.WebControls.Label?
<
Private Sub DataGrid_ItemDataBound(ByVal sender As System.Object,ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)处理DataGrid。 ItemDataBound


如果e.Item.ItemType = ListItemType.Item或e.Item.ItemType = ListItemType.AlternatingItem或e.Item.ItemType = ListItemType。 SelectedItem然后


Dim按钮As LinkBut​​ton = CType(e.Item.Cells(0).Controls(0),LinkBut​​ton)


Dim col作为整数


对于col = 0到e.Item.Cells.Count - 1


e.Item.Cells(col)。属性(onClick)= Page.GetPostBackClientHyperlink(button,col.ToString)


下一页




''这种转换成本非常高。


如果CInt(CType(e.It) em.DataItem,System.data.DataRowView).Item(" ID"))<> myUser.ID然后


CType(e.Item.Controls(2).Controls(1),System.Web.UI.WebControls.Label).Visible = False


结束如果



结束如果




结束子



提前多多谢谢!



Daniel

Hi,



I want to display a Label in a DataGrid according to some condition. I therefore check whether the condition is true in the ItemDateBound EventHandler of the DataGrid. Unfortunately the conversion is extremely costly in performance. Does anybody know how I could set the label (of the whole content of the TableCell) to .Visible = False without converting e.Item.Controls(2) to a System.Web.UI.WebControls.Label?





Private Sub DataGrid_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid.ItemDataBound



If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.SelectedItem Then

Dim button As LinkButton = CType(e.Item.Cells(0).Controls(0), LinkButton)

Dim col As Integer

For col = 0 To e.Item.Cells.Count - 1

e.Item.Cells(col).Attributes("onClick") = Page.GetPostBackClientHyperlink(button, col.ToString)

Next



'' This conversion is EXTREMELY costly.

If CInt(CType(e.Item.DataItem, System.data.DataRowView).Item("ID")) <> myUser.ID Then

CType(e.Item.Controls(2).Controls(1), System.Web.UI.WebControls.Label).Visible = False

End If



End If



End Sub



Thanks a lot in advance!



Daniel

推荐答案

也许我没有抓住实际意义,在我看来,为什么不使用TemplateColumn,它包含一个Label,Visible依赖于getVisible(DataBinder.Eval(Container.DataItem," Id"))。


在Datagrid中,你写< asp:Lable id = "一些"值=''getVisible(...)''/>

页面或用户控件中的
,你给出一种方法

bool getVisible(param )

返回(param!= myuser.id)


我想问一个问题,你怎么能发现性能被阻止了类型转换?谢谢。


我想根据某些条件在DataGrid中显示一个Label。因此,我检查DataGrid的ItemDateBound EventHandler中的条件是否为真。不幸的是,转换的性能极其昂贵。有没有人知道如何将标签(TableCell的整个内容)设置为.Visible = False而不将e.Item.Controls(2)转换为System.Web.UI.WebControls.Label?
<
Private Sub DataGrid_ItemDataBound(ByVal sender As System.Object,ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)处理DataGrid。 ItemDataBound


如果e.Item.ItemType = ListItemType.Item或e.Item.ItemType = ListItemType.AlternatingItem或e.Item.ItemType = ListItemType。 SelectedItem然后


Dim按钮As LinkBut​​ton = CType(e.Item.Cells(0).Controls(0),LinkBut​​ton)


Dim col作为整数


对于col = 0到e.Item.Cells.Count - 1


e.Item.Cells(col)。属性(onClick)= Page.GetPostBackClientHyperlink(button,col.ToString)


下一页




''这种转换成本非常高。


如果CInt(CType(e.It) em.DataItem,System.data.DataRowView).Item(" ID"))<> myUser.ID然后


CType(e.Item.Controls(2).Controls(1),System.Web.UI.WebControls.Label).Visible = False


结束如果



结束如果




结束子



提前多多谢谢!



Daniel

maybe I didn''t catch the actual meaning, in my opinion, why don''t you use TemplateColumn, which contains one Label , the Visible relies on getVisible( DataBinder.Eval(Container.DataItem,"Id")).

in Datagrid, you write <asp:Lable id="some" value=''getVisible(...)'' />

in the page or user control , you give one method
bool getVisible( param )
return (param != myuser.id )


I want to ask one question ,how can you find the performance is blocked by the type transformation? Thanks.


I want to display a Label in a DataGrid according to some condition. I therefore check whether the condition is true in the ItemDateBound EventHandler of the DataGrid. Unfortunately the conversion is extremely costly in performance. Does anybody know how I could set the label (of the whole content of the TableCell) to .Visible = False without converting e.Item.Controls(2) to a System.Web.UI.WebControls.Label?





Private Sub DataGrid_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid.ItemDataBound



If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.SelectedItem Then

Dim button As LinkButton = CType(e.Item.Cells(0).Controls(0), LinkButton)

Dim col As Integer

For col = 0 To e.Item.Cells.Count - 1

e.Item.Cells(col).Attributes("onClick") = Page.GetPostBackClientHyperlink(button, col.ToString)

Next



'' This conversion is EXTREMELY costly.

If CInt(CType(e.Item.DataItem, System.data.DataRowView).Item("ID")) <> myUser.ID Then

CType(e.Item.Controls(2).Controls(1), System.Web.UI.WebControls.Label).Visible = False

End If



End If



End Sub



Thanks a lot in advance!



Daniel


您好Daniel,


至于在aps中更改Label控件的显示问题.net
ItemDataBound中的
datagird单元格。我认为显式转换是唯一的

意味着检索DataGridItem的单元格中的子控件。还有,

是我们可以做的另一种方法是定义一个辅助函数并在

数据绑定表达式中调用它,例如:


< asp:Label ID =" lblTest" RUNAT = QUOT;服务器" Visible =''<%#function name%>''>

< / asp:Label>


该函数可以是成员Page类的功能,并带一些

参数,其中包含关于当前项目的足够信息



希望有帮助。谢谢。


问候,


Steven Cheng

微软在线支持


安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)


在ASP.NET上获取预览whidbey
< a rel =nofollowhref =http://msdn.microsoft.com/asp.net/whidbey/default.aspxtarget =_ blank> http://msdn.microsoft.com/asp.net/whidbey /default.aspx

Hi Daniel,

As for the problem on changing the Label control''s display in aps.net
datagird cell in ItemDataBound. I think the explicit cast is the only
means to retrieve the sub controls in the DataGridItem''s Cells. Also, there
is another way we can do is define a helper function and call it in the
DataBinding Expression ,for example:

<asp:Label ID="lblTest" Runat="server" Visible=''<%# function name %>'' >
</asp:Label>

The function can be a member function of the Page class and take some
parameters which contains the sufficient info
about the current item.
Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


Edward,Steven,


遗憾的是并没有显着改善性能。关于爱德华兹''

的问题:我注意到这个页面需要很长时间才能显示出来。因此,我b $ b注释了部分代码,我认为代价高昂且找到了


如果CInt(CType(e.Item.DataItem,System.data.DataRowView) ).Item(" ID"))<>

myUser.ID然后


CType(e.Item.Controls(2).Controls (1),

System.Web.UI.WebControls.Label).Visible = False


结束如果


是瓶颈。


谢谢!


Daniel


" Steven程[MSFT] QUOT; <,V - ****** @ online.microsoft.com> schrieb im Newsbeitrag

新闻:Vf ************** @ cpmsftngxa10.phx.gbl ...
Edward, Steven,

thanks for your help. I tried you approach which worked perfectly well but
unfortunately does not improve performance significantly. Regarding Edwards''
s question: I noticed this page took long to get displayed. I therefore
commented out parts of the code I assumed being costly and found

If CInt(CType(e.Item.DataItem, System.data.DataRowView).Item("ID")) <>
myUser.ID Then

CType(e.Item.Controls(2).Controls(1),
System.Web.UI.WebControls.Label).Visible = False

End If

to be the bottleneck.

Thank you!

Daniel

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> schrieb im Newsbeitrag
news:Vf**************@cpmsftngxa10.phx.gbl...
嗨丹尼尔,我们可以做的另一种方法是定义辅助函数并在
DataBinding表达式中调用它,例如:

< asp:Label ID =" lblTest" RUNAT = QUOT;服务器" Visible =''<%#function name%>''>
< / asp:Label>

该函数可以是Page类的成员函数并取一些
参数包含关于当前项目的足够信息。
希望有帮助。谢谢。

问候,

Steven Cheng
微软在线支持

获得安全! www.microsoft.com/security
(此帖已提供按原样,没有任何保证,也没有授予
权利。)

在ASP.NET上预览whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Hi Daniel,

As for the problem on changing the Label control''s display in aps.net
datagird cell in ItemDataBound. I think the explicit cast is the only
means to retrieve the sub controls in the DataGridItem''s Cells. Also, there is another way we can do is define a helper function and call it in the
DataBinding Expression ,for example:

<asp:Label ID="lblTest" Runat="server" Visible=''<%# function name %>'' >
</asp:Label>

The function can be a member function of the Page class and take some
parameters which contains the sufficient info
about the current item.
Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx



这篇关于如何在没有昂贵的转换的情况下在DataGrid的ItemDateBound中设置控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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