473,394 Members | 1,916 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,394 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 1529

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...

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.