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
12 2011
It should refresh in the normal build process, but I can't swear to it.
Two alternatives are:
*Rebuild* project/solution
or
right click xsd file in solution explorer, click "Run Custom Tool"
Martin
"Daniel Walzenbach" <da************ **********@freu denberg.de> wrote in message news:uu******** ******@tk2msftn gp13.phx.gbl...
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
Thank you Martin,
I will give it a try.
Daniel
"Martin" <x@y.z> schrieb im Newsbeitrag news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
It should refresh in the normal build process, but I can't swear to it.
Two alternatives are:
*Rebuild* project/solution
or
right click xsd file in solution explorer, click "Run Custom Tool"
Martin
"Daniel Walzenbach" <da************ **********@freu denberg.de> wrote in message news:uu******** ******@tk2msftn gp13.phx.gbl...
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
Hello Diniel,
I was reviewing the thread. It seems that the question is OK now. If you have any more concerns on this issue, please feel free to post here and
we will follow up.
Thanks very much.
Best regards,
Yanhong Huang
Microsoft Community Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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,...
|
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...
|
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...
|
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.
| |
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
|
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.
|
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
|
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
|
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...
|
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,...
| |
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...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |