EditCommandColumn ButtonType=PushButton CSS

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

Maziar Aflatoun

Hi everyone,

Does anyone know how I can add a CSS (Ex. button1 ) to the following Edit
button is ASP .NET?

<asp:EditCommandColumn ButtonType="PushButton" EditText="Edit"
CancelText="Edit" UpdateText="Update"></asp:EditCommandColumn>

I want to change the way my buttons look.

Thank you
Maz.
 
Hi Maz,

You cannot apply the css directly to the column in design view but what you
can do is use the ItemDataBound event of the DataGrid to set the cssclass
onto the button with code like this:

private void pricingRuleDataGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item
||e.Item.ItemType==ListItemType.AlternatingItem
||e.Item.ItemType==ListItemType.EditItem)
{
((WebControl)e.Item.Cells[4].Controls[0]).CssClass = "button1";
}
}

This of course assumes that the button is in the fifth column of the grid.
 
Thank you. I tried it and this is what I get.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:

Line 134: ||e.Item.ItemType==ListItemType.EditItem)
Line 135: {
Line 136: ((WebControl)e.Item.Cells[11].Controls[0]).CssClass =
"button1";
Line 137: }
Line 138:


Thanks
Maz.


Steve Willcock said:
Hi Maz,

You cannot apply the css directly to the column in design view but what
you
can do is use the ItemDataBound event of the DataGrid to set the cssclass
onto the button with code like this:

private void pricingRuleDataGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item
||e.Item.ItemType==ListItemType.AlternatingItem
||e.Item.ItemType==ListItemType.EditItem)
{
((WebControl)e.Item.Cells[4].Controls[0]).CssClass = "button1";
}
}

This of course assumes that the button is in the fifth column of the grid.

--
Steve Willcock (MCSD for Microsoft.NET)
http://www.willcockconsulting.com/

Maziar Aflatoun said:
Hi everyone,

Does anyone know how I can add a CSS (Ex. button1 ) to the following Edit
button is ASP .NET?

<asp:EditCommandColumn ButtonType="PushButton" EditText="Edit"
CancelText="Edit" UpdateText="Update"></asp:EditCommandColumn>

I want to change the way my buttons look.

Thank you
Maz.
 
Thanks I got it... I was pointing to the wrong cell.


Maziar Aflatoun said:
Thank you. I tried it and this is what I get.

Exception Details: System.InvalidCastException: Specified cast is not
valid.

Source Error:

Line 134: ||e.Item.ItemType==ListItemType.EditItem)
Line 135: {
Line 136: ((WebControl)e.Item.Cells[11].Controls[0]).CssClass = "button1";
Line 137: }
Line 138:


Thanks
Maz.


Steve Willcock said:
Hi Maz,

You cannot apply the css directly to the column in design view but what
you
can do is use the ItemDataBound event of the DataGrid to set the cssclass
onto the button with code like this:

private void pricingRuleDataGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item
||e.Item.ItemType==ListItemType.AlternatingItem
||e.Item.ItemType==ListItemType.EditItem)
{
((WebControl)e.Item.Cells[4].Controls[0]).CssClass = "button1";
}
}

This of course assumes that the button is in the fifth column of the
grid.

--
Steve Willcock (MCSD for Microsoft.NET)
http://www.willcockconsulting.com/

Maziar Aflatoun said:
Hi everyone,

Does anyone know how I can add a CSS (Ex. button1 ) to the following
Edit
button is ASP .NET?

<asp:EditCommandColumn ButtonType="PushButton" EditText="Edit"
CancelText="Edit" UpdateText="Update"></asp:EditCommandColumn>

I want to change the way my buttons look.

Thank you
Maz.
 
Sorry for one more question. Once the user clicks Edit is changes to Update
and Cancel. Howerver, I can not get my CSS to bind itself to Cancel as well
too. Any idea?


Thank you




Maziar Aflatoun said:
Thanks I got it... I was pointing to the wrong cell.


Maziar Aflatoun said:
Thank you. I tried it and this is what I get.

Exception Details: System.InvalidCastException: Specified cast is not
valid.

Source Error:

Line 134: ||e.Item.ItemType==ListItemType.EditItem)
Line 135: {
Line 136: ((WebControl)e.Item.Cells[11].Controls[0]).CssClass =
"button1";
Line 137: }
Line 138:


Thanks
Maz.


Steve Willcock said:
Hi Maz,

You cannot apply the css directly to the column in design view but what
you
can do is use the ItemDataBound event of the DataGrid to set the
cssclass
onto the button with code like this:

private void pricingRuleDataGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item
||e.Item.ItemType==ListItemType.AlternatingItem
||e.Item.ItemType==ListItemType.EditItem)
{
((WebControl)e.Item.Cells[4].Controls[0]).CssClass = "button1";
}
}

This of course assumes that the button is in the fifth column of the
grid.

--
Steve Willcock (MCSD for Microsoft.NET)
http://www.willcockconsulting.com/

Hi everyone,

Does anyone know how I can add a CSS (Ex. button1 ) to the following
Edit
button is ASP .NET?

<asp:EditCommandColumn ButtonType="PushButton" EditText="Edit"
CancelText="Edit" UpdateText="Update"></asp:EditCommandColumn>

I want to change the way my buttons look.

Thank you
Maz.
 
Er... not really sure about that one - I think you should be able to use the
same mechanism to do this - not sure why it wouldn't work.

Steve

Maziar Aflatoun said:
Sorry for one more question. Once the user clicks Edit is changes to Update
and Cancel. Howerver, I can not get my CSS to bind itself to Cancel as well
too. Any idea?


Thank you




Maziar Aflatoun said:
Thanks I got it... I was pointing to the wrong cell.


Maziar Aflatoun said:
Thank you. I tried it and this is what I get.

Exception Details: System.InvalidCastException: Specified cast is not
valid.

Source Error:

Line 134: ||e.Item.ItemType==ListItemType.EditItem)
Line 135: {
Line 136: ((WebControl)e.Item.Cells[11].Controls[0]).CssClass =
"button1";
Line 137: }
Line 138:


Thanks
Maz.


message Hi Maz,

You cannot apply the css directly to the column in design view but what
you
can do is use the ItemDataBound event of the DataGrid to set the
cssclass
onto the button with code like this:

private void pricingRuleDataGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item
||e.Item.ItemType==ListItemType.AlternatingItem
||e.Item.ItemType==ListItemType.EditItem)
{
((WebControl)e.Item.Cells[4].Controls[0]).CssClass = "button1";
}
}

This of course assumes that the button is in the fifth column of the
grid.

--
Steve Willcock (MCSD for Microsoft.NET)
http://www.willcockconsulting.com/

Hi everyone,

Does anyone know how I can add a CSS (Ex. button1 ) to the following
Edit
button is ASP .NET?

<asp:EditCommandColumn ButtonType="PushButton" EditText="Edit"
CancelText="Edit" UpdateText="Update"></asp:EditCommandColumn>

I want to change the way my buttons look.

Thank you
Maz.
 
Back
Top