Applying CSS to asp:EditCommandColumn

  • Thread starter Thread starter Maziar Aflatoun
  • Start date Start date
M

Maziar Aflatoun

I'm have a datagrid with 2 buttons Edit and Delete.

<asp:EditCommandColumn ButtonType="PushButton" EditText="Edit"
CancelText="Cancel" UpdateText="Update"></asp:EditCommandColumn>
<asp:ButtonColumn ButtonType="PushButton" Text="Delete"
CommandName="Delete"></asp:ButtonColumn>


Once you click Edit it changes in Edit and Cancel. I like to apply CSS to
my buttons. I got it to work for Edit and Delete. However, I'm having
problem with Cancel? Any idea?

((WebControl)e.Item.Cells[12].Controls[0]).CssClass = "button1";
((WebControl)e.Item.Cells[13].Controls[0]).CssClass = "button1";

How would I apply this css "button1" to my once Edit clicked state?

Thank you
Maziar A.
 
Hi,
I assume you are setting the CssClass in the ItemDataBound event. If so:
when the current item being rendered is of type EditItem then, set the
CssClass for both the controls in the edit command column. The code might
look like this:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
((WebControl)e.Item.Cells[12].Controls[0]).CssClass = "button1";
((WebControl)e.Item.Cells[13].Controls[0]).CssClass = "button1";
}
else if (e.Item.ItemType == ListItemType.EditItem)
{
// Controls[0] is Update
((WebControl)e.Item.Cells[12].Controls[0]).CssClass = "button1";
// Controls[1] is Cancel
((WebControl)e.Item.Cells[12].Controls[1]).CssClass = "button1";
}

Hope this helps.

I'm have a datagrid with 2 buttons Edit and Delete.

<asp:EditCommandColumn ButtonType="PushButton" EditText="Edit"
CancelText="Cancel" UpdateText="Update"></asp:EditCommandColumn>
<asp:ButtonColumn ButtonType="PushButton" Text="Delete"
CommandName="Delete"></asp:ButtonColumn>


Once you click Edit it changes in Edit and Cancel. I like to apply CSS to
my buttons. I got it to work for Edit and Delete. However, I'm having
problem with Cancel? Any idea?

((WebControl)e.Item.Cells[12].Controls[0]).CssClass = "button1";
((WebControl)e.Item.Cells[13].Controls[0]).CssClass = "button1";

How would I apply this css "button1" to my once Edit clicked state?

Thank you
Maziar A.
 
Back
Top