473,834 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmaticall y adding attributes to DataGrid columns

I'm trying to add an attribute to each column header of a DataGrid. I know
that I need to do this within the ItemCreated event of the DataGrid, but I'm
stuck on how to go any further.

I found some info on MSDN on how to do this, but it's doesn't clear any
thing up for me Here's the paragraph and a link to the document:

http://msdn.microsoft.com/library/de...vercontrol.asp

"To add an attribute to the <td> tag, first get the TableCell object that
represents the cell in the DataGrid control to which you want to add the
attribute. The Control.Control s collection for the Item property
(DataGridItemEv entArgs indexer) of the DataGridItemEve ntArgs passed into the
event handler can be used to get the desired TableCell. You can then use the
AttributeCollec tion.Add method of the Attributes collection for the
TableCell to add attributes to the <td> tag."

Can anyone point me in the right direction?
Nov 15 '05 #1
1 7915
Nevermind this question, I figured it out. Here's how I did it in case
anyone wants to know later:

private void DataGrid1_ItemC reated(object sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
ListItemType itemType = (ListItemType)e .Item.ItemType;
if (itemType == ListItemType.He ader)
{
// There's 5 columns in DataGrid1
for (int i = 0; i <= 4; i++)
{
TableCell intCell = (TableCell)e.It em.Controls[i];
intCell.Attribu tes.Add("onmous eover", "this.bgColor=' Silver'");
intCell.Attribu tes.Add("onmous eout", "this.bgColor=' Gainsboro'");
}
}
}

"Mike Irwin" <mi**@faroutfre akyshit.com> wrote in message
news:uL******** *****@TK2MSFTNG P12.phx.gbl...
I'm trying to add an attribute to each column header of a DataGrid. I know that I need to do this within the ItemCreated event of the DataGrid, but I'm stuck on how to go any further.

I found some info on MSDN on how to do this, but it's doesn't clear any
thing up for me Here's the paragraph and a link to the document:

http://msdn.microsoft.com/library/de...vercontrol.asp
"To add an attribute to the <td> tag, first get the TableCell object that
represents the cell in the DataGrid control to which you want to add the
attribute. The Control.Control s collection for the Item property
(DataGridItemEv entArgs indexer) of the DataGridItemEve ntArgs passed into the event handler can be used to get the desired TableCell. You can then use the AttributeCollec tion.Add method of the Attributes collection for the
TableCell to add attributes to the <td> tag."

Can anyone point me in the right direction?

Nov 15 '05 #2

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

Similar topics

12
1928
by: Silvia | last post by:
Hi I have a form and I add buttons programmatically in de form_Load function Anybody know how implements de function button_click if in the designer mode the button doesn't exists Another question In a datagrid control is posible programmatically do autosize columns
2
4555
by: Nicole | last post by:
I am creating template columns programmatically. I have read the msdn article on this and I'm so close. Article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchcreatingwebservercontroltemplatesprogrammatically.asp I have narrowed down the problem comes in when the _DataBinding handler is called and the literal text is being assigned, but I can't figure out beyond that. The main problem is that...
1
3301
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple days of struggling, I figure asking you all (the experts) will keep me from going down some dark and dangerous road. The project I have is a fairly simple one, in theory anyway. The gist is to create a page where the user enters an IDNumber,...
2
1694
by: ringo | last post by:
I've come accross an interesting problem populating an asp.net datagrid. I am trying to bind XML data to a datagrid as I've done in countless other applications, the only difference this time being that the XML I'm getting has attributes within the elements which I need to bind to the grid. Example XML (I need to populate the datagrid with the address, name, and CityStateZip elements): <properties> <record display="properties" no="1">...
2
1344
by: JenC | last post by:
Hi, I need to add columns programmatically to a datagrid I have on my ASP page. I have approx 6 bound columns and I would like to add a few columns dynamically. Basically they are calculated values (i.e. (value/No days) * days in month). Any help on this would be much appreciated as I seem to be going round in circles.
4
5061
by: | last post by:
I have a "form field highlight" javascript that I've added to some of my ASP.NET forms using the following syntax: body.Attributes.Add("onClick", "highlight(event);"); body.Attributes.Add("onKeyUp", "highlight(event);"); Some of my forms have a great many text box controls that I want to highlight.. I would much rather that ASP.NET do the work of looping through all text boxes and applying these two attributes.
3
10391
by: Silvia | last post by:
Hi, I have a form and I add buttons programmatically in de form_Load function. Anybody know how implements de function button_click if in the designer mode the button doesn't exists? I write in visual basic .net: mybutton.Click = New EventHandler (AddressOf DetectedAClick)
2
3571
by: Flack | last post by:
Hey guys, I have a DataGrid and DataTable field in my class : private ImageDataGrid dataGrid1; //ImageDataGrid extends dataGrid and just overides OnMouseDown private DataTable dt = new DataTable("MyTable"); In the classes constructor, after InitializeComponent() I call the following
12
6237
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the datagrid. Once I can get to that point I need some way to be able to add new data only to the new columns that were added. Here is some of my code: //Function For Importing Data From CSV File public DataSet ConnectCSV(string filetable)
0
9799
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
9646
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
10510
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...
1
10548
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,...
0
9331
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...
1
7758
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6954
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();...
1
4427
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
3
3081
bsmnconsultancy
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...

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.