J
Jeff User
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
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