473,734 Members | 2,824 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to set controls in a DataGrid's ItemDateBound without a costly conversion?

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.W ebControls.Labe l?





Private Sub DataGrid_ItemDa taBound(ByVal sender As System.Object, ByVal e As System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles DataGrid.ItemDa taBound



If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType = ListItemType.Al ternatingItem Or e.Item.ItemType = ListItemType.Se lectedItem Then

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

Dim col As Integer

For col = 0 To e.Item.Cells.Co unt - 1

e.Item.Cells(co l).Attributes(" onClick") = Page.GetPostBac kClientHyperlin k(button, col.ToString)

Next



' This conversion is EXTREMELY costly.

If CInt(CType(e.It em.DataItem, System.data.Dat aRowView).Item( "ID")) <> myUser.ID Then

CType(e.Item.Co ntrols(2).Contr ols(1), System.Web.UI.W ebControls.Labe l).Visible = False

End If



End If



End Sub



Thanks a lot in advance!



Daniel

Nov 18 '05 #1
12 2007
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.Data Item,"Id")).

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

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.W ebControls.Labe l?





Private Sub DataGrid_ItemDa taBound(ByVal sender As System.Object, ByVal e As System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles DataGrid.ItemDa taBound



If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType = ListItemType.Al ternatingItem Or e.Item.ItemType = ListItemType.Se lectedItem Then

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

Dim col As Integer

For col = 0 To e.Item.Cells.Co unt - 1

e.Item.Cells(co l).Attributes(" onClick") = Page.GetPostBac kClientHyperlin k(button, col.ToString)

Next



' This conversion is EXTREMELY costly.

If CInt(CType(e.It em.DataItem, System.data.Dat aRowView).Item( "ID")) <> myUser.ID Then

CType(e.Item.Co ntrols(2).Contr ols(1), System.Web.UI.W ebControls.Labe l).Visible = False

End If



End If



End Sub



Thanks a lot in advance!



Daniel

Nov 18 '05 #2
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

Nov 18 '05 #3
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.It em.DataItem, System.data.Dat aRowView).Item( "ID")) <>
myUser.ID Then

CType(e.Item.Co ntrols(2).Contr ols(1),
System.Web.UI.W ebControls.Labe l).Visible = False

End If

to be the bottleneck.

Thank you!

Daniel

"Steven Cheng[MSFT]" <v-******@online.m icrosoft.com> schrieb im Newsbeitrag
news:Vf******** ******@cpmsftng xa10.phx.gbl...
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

Nov 18 '05 #4
Looks like you would end up displaying the ID if it wasn't *your* userID - so you would display other user ID?

What happens to other fields in this row? If the whole row should be affected, a filter on the dataview might be the way to go - probably requiring a mod to your data source.

A bit more info on the wider problem may reveal a better solution.

Martin

"Daniel Walzenbach" <da************ **********@freu denberg.de> wrote in message news:uu******** ******@tk2msftn gp13.phx.gbl...
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.W ebControls.Labe l?





Private Sub DataGrid_ItemDa taBound(ByVal sender As System.Object, ByVal e As System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles DataGrid.ItemDa taBound



If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType = ListItemType.Al ternatingItem Or e.Item.ItemType = ListItemType.Se lectedItem Then

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

Dim col As Integer

For col = 0 To e.Item.Cells.Co unt - 1

e.Item.Cells(co l).Attributes(" onClick") = Page.GetPostBac kClientHyperlin k(button, col.ToString)

Next



' This conversion is EXTREMELY costly.

If CInt(CType(e.It em.DataItem, System.data.Dat aRowView).Item( "ID")) <> myUser.ID Then

CType(e.Item.Co ntrols(2).Contr ols(1), System.Web.UI.W ebControls.Labe l).Visible = False

End If



End If



End Sub



Thanks a lot in advance!



Daniel

Nov 18 '05 #5
Martin,



I have a DataGrid which displays orders users have made.



Edit | OrderID | Order Description | Order ...

--------|---------------|-----------------------|--------------------

Edit | 1 | Some Order |

| 2 | Another Order |

Edit | 3 | Third Order |

Edit | 4 | Forth Order |



Since I want everybody to be able to see (in a read-only fashion) all orders I modified a DataGrid in that way that a click on the Columns "OrderID", "Order Description", "Order ..." redirects the actual user to another page where he/she can view the order details. If though the logged in user is the same user as the one who created an order I want him to be able to click on the first column "Edit" where he gets redirected to another page where he/she can edit his order. As the logged in user should see which order he can edit I want to display a label in the first column reflecting his/hers possibilities (In this example the user could edit all orders but "Another Order"). Fact is, that everything works perfectly well as it should, but the performance is not as want it to be.



Thanks for your help! I hope this description helps you better to understand what I want to do.



Daniel
"Martin" <x@y.z> schrieb im Newsbeitrag news:ur******** ******@TK2MSFTN GP12.phx.gbl...
Looks like you would end up displaying the ID if it wasn't *your* userID - so you would display other user ID?

What happens to other fields in this row? If the whole row should be affected, a filter on the dataview might be the way to go - probably requiring a mod to your data source.

A bit more info on the wider problem may reveal a better solution.

Martin

"Daniel Walzenbach" <da************ **********@freu denberg.de> wrote in message news:uu******** ******@tk2msftn gp13.phx.gbl...
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.W ebControls.Labe l?





Private Sub DataGrid_ItemDa taBound(ByVal sender As System.Object, ByVal e As System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles DataGrid.ItemDa taBound



If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType = ListItemType.Al ternatingItem Or e.Item.ItemType = ListItemType.Se lectedItem Then

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

Dim col As Integer

For col = 0 To e.Item.Cells.Co unt - 1

e.Item.Cells(co l).Attributes(" onClick") = Page.GetPostBac kClientHyperlin k(button, col.ToString)

Next



' This conversion is EXTREMELY costly.

If CInt(CType(e.It em.DataItem, System.data.Dat aRowView).Item( "ID")) <> myUser.ID Then

CType(e.Item.Co ntrols(2).Contr ols(1), System.Web.UI.W ebControls.Labe l).Visible = False

End If



End If



End Sub



Thanks a lot in advance!



Daniel

Nov 18 '05 #6
Hi Daniel,

I see.

I presume you have a dataset to populate the datagrid. I would try adding a field to the dataset to determine if the edit can be done, and using that as the datasource for the first column. Might not be any faster though - you'd have to try it. This solution depends on how your dataset is created - once for every user, or on a per user basis.

Also, you would probably find some performance improvement if you used a typed dataset - you wouldn't have to index your row by column name at runtime.

However like Steven says, it's probably the effort of getting the sub controls in the datagrid that is doing the damage - test this by sticking some dummy statement in place of CType(e.Item.Co ntrols(2).Contr ols(1), System.Web.UI.W ebControls.Labe l).Visible = False
As a minor point, in the above statement, you shouldn't have to bother doing the CType to Label, as the Control base class also has the Visible property.
From that statement it looks like you have other sub controls in that cell of the datagrid. Why do you have Controls(2).Con trols(1)? Can you simplfiy that?

Interested to hear how it goes.
Martin
"Daniel Walzenbach" <da************ **********@freu denberg.de> wrote in message news:uF******** *******@tk2msft ngp13.phx.gbl.. .
Martin,



I have a DataGrid which displays orders users have made.



Edit | OrderID | Order Description | Order ...

--------|---------------|-----------------------|--------------------

Edit | 1 | Some Order |

| 2 | Another Order |

Edit | 3 | Third Order |

Edit | 4 | Forth Order |



Since I want everybody to be able to see (in a read-only fashion) all orders I modified a DataGrid in that way that a click on the Columns "OrderID", "Order Description", "Order ..." redirects the actual user to another page where he/she can view the order details. If though the logged in user is the same user as the one who created an order I want him to be able to click on the first column "Edit" where he gets redirected to another page where he/she can edit his order. As the logged in user should see which order he can edit I want to display a label in the first column reflecting his/hers possibilities (In this example the user could edit all orders but "Another Order"). Fact is, that everything works perfectly well as it should, but the performance is not as want it to be.



Thanks for your help! I hope this description helps you better to understand what I want to do.



Daniel
"Martin" <x@y.z> schrieb im Newsbeitrag news:ur******** ******@TK2MSFTN GP12.phx.gbl...
Looks like you would end up displaying the ID if it wasn't *your* userID - so you would display other user ID?

What happens to other fields in this row? If the whole row should be affected, a filter on the dataview might be the way to go - probably requiring a mod to your data source.

A bit more info on the wider problem may reveal a better solution.

Martin

"Daniel Walzenbach" <da************ **********@freu denberg.de> wrote in message news:uu******** ******@tk2msftn gp13.phx.gbl...
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.W ebControls.Labe l?





Private Sub DataGrid_ItemDa taBound(ByVal sender As System.Object, ByVal e As System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles DataGrid.ItemDa taBound



If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType = ListItemType.Al ternatingItem Or e.Item.ItemType = ListItemType.Se lectedItem Then

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

Dim col As Integer

For col = 0 To e.Item.Cells.Co unt - 1

e.Item.Cells(co l).Attributes(" onClick") = Page.GetPostBac kClientHyperlin k(button, col.ToString)

Next



' This conversion is EXTREMELY costly.

If CInt(CType(e.It em.DataItem, System.data.Dat aRowView).Item( "ID")) <> myUser.ID Then

CType(e.Item.Co ntrols(2).Contr ols(1), System.Web.UI.W ebControls.Labe l).Visible = False

End If



End If



End Sub



Thanks a lot in advance!



Daniel

Nov 18 '05 #7
Hi Martin,



Thanks for the tip using the visible property of the control instead of the label. This saves one cast :-)



Regarding your question why I cast from e.Item.Controls (2).Controls(1) , I pasted a part of my DataGrid (updated as you/Steve suggested).



<Columns>

<asp:ButtonColu mn Visible="False" CommandName="Se lect"></asp:ButtonColum n>

<asp:BoundColum n Visible="False" DataField="Vorg ang_OIDVorgang" ></asp:BoundColumn >

<asp:TemplateCo lumn ItemStyle-Width="60px" ItemStyle-HorizontalAlign ="Center">

<ItemTemplate >

<asp:Label CssClass="Butto nInGrid" text=" Abteilungssicht " Runat="server" ID="LabelAbteil ungssicht" Visible='<%# Abteilungssicht Anzeigen(DataBi nder.Eval(Conta iner.DataItem, "Vorgang_IDKost enstelle")) %>'></asp:Label>

</ItemTemplate>

</asp:TemplateCol umn>



As you can see there are two hidden columns (which explains e.Item.Controls (2)) plus a label in the third column. Therefore e.Item.Controls (2).Controls(0) is a System.Web.UI.L iteralControl and that's the reason why I have to cast e.Item.Controls (2).Controls(1) witch is the actual label.



Daniel

"Martin" <x@y.z> schrieb im Newsbeitrag news:uY******** ******@tk2msftn gp13.phx.gbl...
Hi Daniel,

I see.

I presume you have a dataset to populate the datagrid. I would try adding a field to the dataset to determine if the edit can be done, and using that as the datasource for the first column. Might not be any faster though - you'd have to try it. This solution depends on how your dataset is created - once for every user, or on a per user basis.

Also, you would probably find some performance improvement if you used a typed dataset - you wouldn't have to index your row by column name at runtime.

However like Steven says, it's probably the effort of getting the sub controls in the datagrid that is doing the damage - test this by sticking some dummy statement in place of CType(e.Item.Co ntrols(2).Contr ols(1), System.Web.UI.W ebControls.Labe l).Visible = False
As a minor point, in the above statement, you shouldn't have to bother doing the CType to Label, as the Control base class also has the Visible property.
From that statement it looks like you have other sub controls in that cell of the datagrid. Why do you have Controls(2).Con trols(1)? Can you simplfiy that?

Interested to hear how it goes.
Martin
"Daniel Walzenbach" <da************ **********@freu denberg.de> wrote in message news:uF******** *******@tk2msft ngp13.phx.gbl.. .
Martin,



I have a DataGrid which displays orders users have made.



Edit | OrderID | Order Description | Order ...

--------|---------------|-----------------------|--------------------

Edit | 1 | Some Order |

| 2 | Another Order |

Edit | 3 | Third Order |

Edit | 4 | Forth Order |



Since I want everybody to be able to see (in a read-only fashion) all orders I modified a DataGrid in that way that a click on the Columns "OrderID", "Order Description", "Order ..." redirects the actual user to another page where he/she can view the order details. If though the logged in user is the same user as the one who created an order I want him to be able to click on the first column "Edit" where he gets redirected to another page where he/she can edit his order. As the logged in user should see which order he can edit I want to display a label in the first column reflecting his/hers possibilities (In this example the user could edit all orders but "Another Order"). Fact is, that everything works perfectly well as it should, but the performance is not as want it to be.



Thanks for your help! I hope this description helps you better to understand what I want to do.



Daniel
"Martin" <x@y.z> schrieb im Newsbeitrag news:ur******** ******@TK2MSFTN GP12.phx.gbl...
Looks like you would end up displaying the ID if it wasn't *your* userID - so you would display other user ID?

What happens to other fields in this row? If the whole row should be affected, a filter on the dataview might be the way to go - probably requiring a mod to your data source.

A bit more info on the wider problem may reveal a better solution.

Martin

"Daniel Walzenbach" <da************ **********@freu denberg.de> wrote in message news:uu******** ******@tk2msftn gp13.phx.gbl...
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.W ebControls.Labe l?





Private Sub DataGrid_ItemDa taBound(ByVal sender As System.Object, ByVal e As System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles DataGrid.ItemDa taBound



If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType = ListItemType.Al ternatingItem Or e.Item.ItemType = ListItemType.Se lectedItem Then

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

Dim col As Integer

For col = 0 To e.Item.Cells.Co unt - 1

e.Item.Cells(co l).Attributes(" onClick") = Page.GetPostBac kClientHyperlin k(button, col.ToString)

Next



' This conversion is EXTREMELY costly.

If CInt(CType(e.It em.DataItem, System.data.Dat aRowView).Item( "ID")) <> myUser.ID Then

CType(e.Item.Co ntrols(2).Contr ols(1), System.Web.UI.W ebControls.Labe l).Visible = False

End If



End If



End Sub



Thanks a lot in advance!



Daniel

Nov 18 '05 #8
Okay,

Have you tried a typed dataset with the display/no display info in there? I don't suppose the cast saving made any time difference(?)

Martin
"Daniel Walzenbach" <da************ **********@freu denberg.de> wrote in message news:O0******** ******@tk2msftn gp13.phx.gbl...
Hi Martin,



Thanks for the tip using the visible property of the control instead of the label. This saves one cast :-)



Regarding your question why I cast from e.Item.Controls (2).Controls(1) , I pasted a part of my DataGrid (updated as you/Steve suggested).



<Columns>

<asp:ButtonColu mn Visible="False" CommandName="Se lect"></asp:ButtonColum n>

<asp:BoundColum n Visible="False" DataField="Vorg ang_OIDVorgang" ></asp:BoundColumn >

<asp:TemplateCo lumn ItemStyle-Width="60px" ItemStyle-HorizontalAlign ="Center">

<ItemTemplate >

<asp:Label CssClass="Butto nInGrid" text=" Abteilungssicht " Runat="server" ID="LabelAbteil ungssicht" Visible='<%# Abteilungssicht Anzeigen(DataBi nder.Eval(Conta iner.DataItem, "Vorgang_IDKost enstelle")) %>'></asp:Label>

</ItemTemplate>

</asp:TemplateCol umn>



As you can see there are two hidden columns (which explains e.Item.Controls (2)) plus a label in the third column. Therefore e.Item.Controls (2).Controls(0) is a System.Web.UI.L iteralControl and that's the reason why I have to cast e.Item.Controls (2).Controls(1) witch is the actual label.



Daniel



"Martin" <x@y.z> schrieb im Newsbeitrag news:uY******** ******@tk2msftn gp13.phx.gbl...
Hi Daniel,

I see.

I presume you have a dataset to populate the datagrid. I would try adding a field to the dataset to determine if the edit can be done, and using that as the datasource for the first column. Might not be any faster though - you'd have to try it. This solution depends on how your dataset is created - once for every user, or on a per user basis.

Also, you would probably find some performance improvement if you used a typed dataset - you wouldn't have to index your row by column name at runtime.

However like Steven says, it's probably the effort of getting the sub controls in the datagrid that is doing the damage - test this by sticking some dummy statement in place of CType(e.Item.Co ntrols(2).Contr ols(1), System.Web.UI.W ebControls.Labe l).Visible = False
As a minor point, in the above statement, you shouldn't have to bother doing the CType to Label, as the Control base class also has the Visible property.
From that statement it looks like you have other sub controls in that cell of the datagrid. Why do you have Controls(2).Con trols(1)? Can you simplfiy that?

Interested to hear how it goes.
Martin
"Daniel Walzenbach" <da************ **********@freu denberg.de> wrote in message news:uF******** *******@tk2msft ngp13.phx.gbl.. .
Martin,



I have a DataGrid which displays orders users have made.



Edit | OrderID | Order Description | Order ...

--------|---------------|-----------------------|--------------------

Edit | 1 | Some Order |

| 2 | Another Order |

Edit | 3 | Third Order |

Edit | 4 | Forth Order |



Since I want everybody to be able to see (in a read-only fashion) all orders I modified a DataGrid in that way that a click on the Columns "OrderID", "Order Description", "Order ..." redirects the actual user to another page where he/she can view the order details. If though the logged in user is the same user as the one who created an order I want him to be able to click on the first column "Edit" where he gets redirected to another page where he/she can edit his order. As the logged in user should see which order he can edit I want to display a label in the first column reflecting his/hers possibilities (In this example the user could edit all orders but "Another Order"). Fact is, that everything works perfectly well as it should, but the performance is not as want it to be.



Thanks for your help! I hope this description helps you better to understand what I want to do.



Daniel
"Martin" <x@y.z> schrieb im Newsbeitrag news:ur******** ******@TK2MSFTN GP12.phx.gbl...
Looks like you would end up displaying the ID if it wasn't *your* userID - so you would display other user ID?

What happens to other fields in this row? If the whole row should be affected, a filter on the dataview might be the way to go - probably requiring a mod to your data source.

A bit more info on the wider problem may reveal a better solution.

Martin

"Daniel Walzenbach" <da************ **********@freu denberg.de> wrote in message news:uu******** ******@tk2msftn gp13.phx.gbl...
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.W ebControls.Labe l?





Private Sub DataGrid_ItemDa taBound(ByVal sender As System.Object, ByVal e As System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles DataGrid.ItemDa taBound



If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType = ListItemType.Al ternatingItem Or e.Item.ItemType = ListItemType.Se lectedItem Then

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

Dim col As Integer

For col = 0 To e.Item.Cells.Co unt - 1

e.Item.Cells(co l).Attributes(" onClick") = Page.GetPostBac kClientHyperlin k(button, col.ToString)

Next



' This conversion is EXTREMELY costly.

If CInt(CType(e.It em.DataItem, System.data.Dat aRowView).Item( "ID")) <> myUser.ID Then

CType(e.Item.Co ntrols(2).Contr ols(1), System.Web.UI.W ebControls.Labe l).Visible = False

End If



End If



End Sub



Thanks a lot in advance!



Daniel

Nov 18 '05 #9
Indeed, one cast won't make any big difference but nevertheless.

I try to avoid using typed dataset since you are completely lost when your datastructure changes (I have not found any way to "refresh" a typed dataset when structure changes which leaves me in the position to make the changes by my own). I suppose, I am going to create the hyperlink on the server, eliminate the click event for the first visible column and place the hyperlink right in there. I assume this will work with satisfying performance :-)



Thanks again for your incitation.



Daniel

"Martin" <x@y.z> schrieb im Newsbeitrag news:uo******** ******@TK2MSFTN GP11.phx.gbl...

Okay,

Have you tried a typed dataset with the display/no display info in there? I don't suppose the cast saving made any time difference(?)

Martin
"Daniel Walzenbach" <da************ **********@freu denberg.de> wrote in message news:O0******** ******@tk2msftn gp13.phx.gbl...
Hi Martin,



Thanks for the tip using the visible property of the control instead of the label. This saves one cast :-)



Regarding your question why I cast from e.Item.Controls (2).Controls(1) , I pasted a part of my DataGrid (updated as you/Steve suggested).



<Columns>

<asp:ButtonColu mn Visible="False" CommandName="Se lect"></asp:ButtonColum n>

<asp:BoundColum n Visible="False" DataField="Vorg ang_OIDVorgang" ></asp:BoundColumn >

<asp:TemplateCo lumn ItemStyle-Width="60px" ItemStyle-HorizontalAlign ="Center">

<ItemTemplate >

<asp:Label CssClass="Butto nInGrid" text=" Abteilungssicht " Runat="server" ID="LabelAbteil ungssicht" Visible='<%# Abteilungssicht Anzeigen(DataBi nder.Eval(Conta iner.DataItem, "Vorgang_IDKost enstelle")) %>'></asp:Label>

</ItemTemplate>

</asp:TemplateCol umn>



As you can see there are two hidden columns (which explains e.Item.Controls (2)) plus a label in the third column. Therefore e.Item.Controls (2).Controls(0) is a System.Web.UI.L iteralControl and that's the reason why I have to cast e.Item.Controls (2).Controls(1) witch is the actual label.



Daniel



"Martin" <x@y.z> schrieb im Newsbeitrag news:uY******** ******@tk2msftn gp13.phx.gbl...
Hi Daniel,

I see.

I presume you have a dataset to populate the datagrid. I would try adding a field to the dataset to determine if the edit can be done, and using that as the datasource for the first column. Might not be any faster though - you'd have to try it. This solution depends on how your dataset is created - once for every user, or on a per user basis.

Also, you would probably find some performance improvement if you used a typed dataset - you wouldn't have to index your row by column name at runtime.

However like Steven says, it's probably the effort of getting the sub controls in the datagrid that is doing the damage - test this by sticking some dummy statement in place of CType(e.Item.Co ntrols(2).Contr ols(1), System.Web.UI.W ebControls.Labe l).Visible = False
As a minor point, in the above statement, you shouldn't have to bother doing the CType to Label, as the Control base class also has the Visible property.
From that statement it looks like you have other sub controls in that cell of the datagrid. Why do you have Controls(2).Con trols(1)? Can you simplfiy that?

Interested to hear how it goes.
Martin
"Daniel Walzenbach" <da************ **********@freu denberg.de> wrote in message news:uF******** *******@tk2msft ngp13.phx.gbl.. .
Martin,



I have a DataGrid which displays orders users have made.



Edit | OrderID | Order Description | Order ...

--------|---------------|-----------------------|--------------------

Edit | 1 | Some Order |

| 2 | Another Order |

Edit | 3 | Third Order |

Edit | 4 | Forth Order |



Since I want everybody to be able to see (in a read-only fashion) all orders I modified a DataGrid in that way that a click on the Columns "OrderID", "Order Description", "Order ..." redirects the actual user to another page where he/she can view the order details. If though the logged in user is the same user as the one who created an order I want him to be able to click on the first column "Edit" where he gets redirected to another page where he/she can edit his order. As the logged in user should see which order he can edit I want to display a label in the first column reflecting his/hers possibilities (In this example the user could edit all orders but "Another Order"). Fact is, that everything works perfectly well as it should, but the performance is not as want it to be.



Thanks for your help! I hope this description helps you better to understand what I want to do.



Daniel
"Martin" <x@y.z> schrieb im Newsbeitrag news:ur******** ******@TK2MSFTN GP12.phx.gbl...
Looks like you would end up displaying the ID if it wasn't *your* userID - so you would display other user ID?

What happens to other fields in this row? If the whole row should be affected, a filter on the dataview might be the way to go - probably requiring a mod to your data source.

A bit more info on the wider problem may reveal a better solution.

Martin

"Daniel Walzenbach" <da************ **********@freu denberg.de> wrote in message news:uu******** ******@tk2msftn gp13.phx.gbl...
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.W ebControls.Labe l?





Private Sub DataGrid_ItemDa taBound(ByVal sender As System.Object, ByVal e As System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles DataGrid.ItemDa taBound



If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType = ListItemType.Al ternatingItem Or e.Item.ItemType = ListItemType.Se lectedItem Then

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

Dim col As Integer

For col = 0 To e.Item.Cells.Co unt - 1

e.Item.Cells(co l).Attributes(" onClick") = Page.GetPostBac kClientHyperlin k(button, col.ToString)

Next



' This conversion is EXTREMELY costly.

If CInt(CType(e.It em.DataItem, System.data.Dat aRowView).Item( "ID")) <> myUser.ID Then

CType(e.Item.Co ntrols(2).Contr ols(1), System.Web.UI.W ebControls.Labe l).Visible = False

End If



End If



End Sub



Thanks a lot in advance!



Daniel

Nov 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1490
by: Jason | last post by:
I am pretty new to C# so bare with me... The design of my website utilizes tables on every page that look almost identical, save the data they are displaying. I have written the code to create the body of these tables using a DataGrid, so I can dynamically add rows to the table without modifying the HTML. Now, I want to put this DataGrid into a user control that I can include in the HTML code, then control the behavior of that DataGrid...
5
2377
by: sdbranum | last post by:
I have been using Visual C#.NET to code a large project having many data adapters, data sets, datagrids, multiple forms with tab pages, each containing various controls (mostly label, text boxes, check boxes, date pickers, combo boxes and datagrids). I have been coding alone on this project for about a year, and I have experienced many problems which have not been addressed by various SP's, including the recent SP1 to Framework.NET 1.1,...
0
1632
by: Phil S. | last post by:
I'm having dreadful trouble putting a simple composite control into the DataGrid cell, so I'm hoping someone might have stumbled across this problem before and have some advice. My composite control is a date picker which contains a couple of basic text, drop down and image button controls. My control follows the composite design guidelines carefully and behaves perfectly when used on a web page. It uses ViewState and gets events from is...
1
1130
by: Machi | last post by:
Can anyone provide any advice or article on creating DataGrid and bind it with data but for every column of data, there may be different Server Controls. To make it clear, let say i want bind 1 field in one DataGrid, but for the only field i want to bind, i may have Label control from rows 1 - 5 and , i want to bind checkboxes to rows from row 6 - 8 and i want to bind again the label controls from row 9 - 11. Can i do that in DAtagrid in ASP.NET...
3
2570
by: Nhat Yen | last post by:
Hi everyone, I don't know why all the controls of the Table class (server control) has to be reconstructed for each page load. The MSDN said that it is because the children controls are not the Table properties. But why other controls like ListBox or DataGrid can persist their child controls? I'm very confused about this.
2
6563
by: Asha | last post by:
greetings, i'm loading a datagrid and my gird has checkbox, i want these checkboxex to be check based on the value from the db? can someone please show me the code for it? thanks
4
1905
by: Paul | last post by:
HI I have some controls under a datagrid and the datagrid can have 1 to 10 items. I would like to place some other controls just below the datagrid so need to somehow dynamically place the controls when the page loads. Any sample code or ideas? thanks. -- Paul G Software engineer.
0
1330
by: Sue | last post by:
I'm missing something very simple here, and I need an answer fairly quick if possible. I'm behind on this project now because of this... Code examples below question... I have a datagrid (DG) that I've pared down to the bare essentials. The two controls involved (MyButton and MyValue) are created in the DG_ItemCreated sub and added to the two placeholders in the datagrid. If the button is clicked, the DG_ItemCommand grabs the button's
15
2188
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) Dim dSet As DataSet Dim sqlConn As SqlConnection Dim sqlDapter As SqlDataAdapter sqlConn = New SqlConnection("Data Source=AD\SQLEXPRESS;Initial
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8777
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9452
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9184
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6033
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4813
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.