473,387 Members | 1,693 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,387 software developers and data experts.

set html attributes of templateColumn and/or change type

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
text.
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
nothing
}
}
}

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?

Thanks
jeff
Jan 2 '06 #1
0 1589

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

Similar topics

4
by: VK | last post by:
09/30/03 Phil Powell posted his "Radio buttons do not appear checked" question. This question led to a long discussion about the naming rules applying to variables, objects, methods and properties...
7
by: Tim Mulholland | last post by:
I have an issue i can work around, but i'm trying to figure out what i'm "supposed" to do. i have a line of HTML/ASP.NET code inside a repeater that is something like this <a...
4
by: Arthur Dent | last post by:
Hello all, ive been programming with ASP.NET since it came out, but am just getting my feet with now with v.2. Ive noticed something strange in the way my HTML tables get rendered with 2. I use...
2
by: Joe | last post by:
Hello All: I am writing to ask for your opinions. I have a colleague who combines his code with the markup used to display the code (reckoning back to classic ASP). Here's an example of a...
3
by: rockdale | last post by:
Hi, All: I have a datagrid with TemplateColumn as following: <asp:TemplateColumn Visible="False" > <ItemStyle Width="0px"></ItemStyle> <ItemTemplate> <asp:Label id="lblMin_Value"...
11
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the JavaScript code contains certain characters, such as & or...
1
by: Tor Inge Rislaa | last post by:
Adding HTML tags to data from SQL server When dragging a table on to a web form in an ASP.NET 2.0 application, the connection is established and the data is displayed in a DataGrid. Is it...
1
by: Big George | last post by:
Hello, Controls on webpage: - Datagrid - TextBox Datagrid has Delete button: <asp:TemplateColumn HeaderText="Borrar"> <HeaderStyle Width="10%"></HeaderStyle>
5
by: dwmartin18 | last post by:
Hello everyone. I have quite the puzzling problem with a script I have been working on lately. I have created a function that can be called to create a new html element (e.g. input, select, div,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.