473,320 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can you customize individual data items in a DataGrid?

The description given in "Customizing Items Dynamically in the DataList or
DataGrid Web Server Control"
(http://msdn.microsoft.com/library/de...-us/dv_vbCode/
html/vbtskCodeCustomizingItemsDynamicallyInDataListWebC ontrolVisualBasic.asp
) says "The examples use the DataList control, but apply to the DataGrid
control as well". From what I've experienced, however, that claim isn't
quite valid, at least in the case (the one I'm concerned about) where the
customization depends on the data values (e.g. how you want to display a
given column's contents depends on what the value of the column is for that
record).

Here is the example given:
Private Sub DataList1_ItemDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) _
Handles DataList1.ItemDataBound
Dim dob As DateTime
Dim doblabel As Label
doblabel = CType(e.Item.FindControl("Label1"), Label)
dob = CType(doblabel.Text, DateTime)
If dob.Month = Today.Month Then
e.Item.BackColor = Color.Yellow
End If
End SubHowever, as far as I can see you can't use this method with a
DataGrid. Ina DataGrid, the Item property of "e" is of type DataGridItem,
which corresponds to an individual record/row in the table. From what I can
see, the column values of theDataGridItem are accessed through the Cells
property.
http://www.datawebcontrols.com/faqs/...tents.shtmlhas
an example where a column's field value is retrieved by a call to
"e.Item.Cells(n).Text" .The catch is that in that example, "e" is of type
DataGridCommandEventArgs, while "e" in the ItemDataBound event for the
DataGrid is of type DataGridItemEventArgs.I have found that within the
ItemDataBound method, a call to e.Item.Cells(n).Text returns the *name* of
the data field, not its value.The DataGridItem does have a Controls
property, but these controls don't even havea Name property, so the
FindControl call used above produces an error.Does anyone know of a way to
get this to work for a DataGrid?Bob Rosen


Jul 21 '05 #1
0 1528

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

Similar topics

0
by: Christian Dokman | last post by:
Hello, I'd like to know if it is possible to customize a button column in a datagrid. I'd like to do the following: * Give an item in the buttoncolumn a different colour when the mouse goes...
0
by: Maria | last post by:
Hi I am new to .NET and would like to know how do we customize the apprearance of a datagrid Precisely, I would like to make ONE row appear in BOLD, and I would like to specify the number of...
3
by: Brian Smith | last post by:
I have a .aspx page (we'll call it Form1) with a datagrid on it. The datagrid is populated from a dataset that I manually entered data into (the data isn't in a database). The datagrid on Form1...
1
by: James Lennon | last post by:
How can I customize a DataGrid row based on the row properties. For istance if a column is 0 make the row bold or red. I have only been able to format a datagrid based on columns. James
1
by: Will Lastname | last post by:
I am working on an EditCommandColumn for editing/deleting items from a datagrid. I am wondering if it is possible to specify height, width, and other various attributes to the textboxes that are...
0
by: Mitkip | last post by:
Does someone know how can I make a user control which allow me to customize it like a datagrid or a repeater ... For example, I would like to call my control in an aspx page like this : <%@...
0
by: Bob Rosen | last post by:
The description given in "Customizing Items Dynamically in the DataList or DataGrid Web Server Control" (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vbCode/...
2
by: Gummy | last post by:
Hello All, I have a webpage that has two dropdown listboxes. Based on what is selected in these dropdown listboxes, it filters a DataGrid . That works fine. In the DataGrid , when I go to edit...
1
by: Mike | last post by:
Hello all, Is there a way to change the ItemTemplate based on the data that is being shown? For instance, I have a dataset, contains two fields (NAME, STATE). I want to show all the records...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.