By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,322 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,322 IT Pros & Developers. It's quick & easy.

set html attributes of templateColumn and/or change type

P: n/a
I have my datagrid running pretty much with a EditCommandColumn and
some TemplateColumn columns.

There are two types of appearance changes I would like to make
programatically from my C# code depending on various conditions.

Column items are typical Labels in <ItemTemplate> and TextBoxes in
<EditItemTemplate> forms.
When the user clicks Edit, I would like to do the following:

1) If I determine (based on inderlying data) that I would like to set
a column to readonly I would also like to change the color of the
The readonly property is working, but the color is not working.
Here is what I try:

//Data is not bound to the editable row
protected void dgTable_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
if(e.Item.ItemType == ListItemType.EditItem)

//Get a reference to the editable Textbox item
TextBox tbUnique = (TextBox)e.Item.Cells[7].Controls[1];
if (tbUnique.Text.Trim() == "NA")
tbUnique.Attributes.Add("ReadOnly","True"); //works
tbUnique.Attributes.Add("ForeColor","'#cc9933'"); //Does

If I place the ForeColor="#cc9933" attribute in the HTML/asp code, it
works, but of course is always the same color

Is there a different approach or perhaps in a different event?

2) The other thing I would like to do is be able to change the type of
item (when in edit mode) to either a Textbox or a Label depending on
if I want the item to be editable/ReadOnly in this particular case.
This would be more ideal than the above.

Is this doable?

Jan 2 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.