Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

buttoncolumn itemstyle-cssclass

Status
Not open for further replies.

TomTT

Programmer
Jun 3, 2002
55
US
I'm trying to use a ButtonColumn in a datagrid and add some style attributes to the buttons.

<ASP:ButtonColumn text=&quot;Send Update&quot;
Itemstyle-CssClass=&quot;colbutton&quot; ButtonType=&quot;PushButton&quot;
CommandName=&quot;DoUpdate&quot; />

I have a CSS style sheet in the head of the page:

<Style ref=&quot;stylesheet&quot; type=&quot;text/css&quot;>
<!--
.ColButton{ background-color:#FFFFCC;
color:#996633;
width:100px;
Height:20px;
}
-->
</Style>

I can successfully attache the stylesheet to other objects such as the datagrid, but can't seem to get the buttoncolumn to take the style.

What am I missing?

Thanks
Tom T
 
are you sure it's not case sensitive?

just a thought

Daren J. Lahey
Just another computer guy...
FAQ183-874 contains &quot;Suggestions for Getting Quick and Appropriate Answers&quot; to your questions.
Support your forums TODAY!
 
I did a quick test to see if case sensitivity was the issue, but it didn't seem to be.

However, are you declaring your class of type Button or type Input?

Try modifying your css to say:

<Style ref=&quot;stylesheet&quot; type=&quot;text/css&quot;>
<!--
Input.ColButton{ background-color:#FFFFCC;
color:#996633;
width:100px;
Height:20px;
}
-->
</Style>

I was able to get it working on mine, but only if it was of type Input.

Nice yellow/brown combo btw
:)

D'Arcy
 
Thanks D'Arcy.

VB isn't case sensitive like C# or java languages.

I added the Input type to the ButtomColumn in the
script (Input.ButtonColumn), but didn't see any change.

I'm working on a test file for this so I'm not using code-behind. I'm not declaring the button at all. If I was putting the code in codebehind, I guess I could declare it as input or button.

I still think I'm missing something basic here.

Can you post or e-mail me the example you got working. It may point out what I'm missing.

Thanks for taking the time to help.

Regards,
Tom T
 
Hey Tom,

K, I figured a bit more out, and I think I see the problem.

The reason that my first test worked was because I was just using a regular button, not a buttoncolumn inside a data grid. I did another test here at home, and here's what I found out:

When you set the Itemstyle-CssClass property of the button column, you're actually setting the css class for the <tr> tag that gets generated, not for any controls found within. thats why your button looks the same.

Unfortunately, I havn't found a way to set the style of the control specifically...yet. But I did find a work around, but it will only work if all of your buttons on your page use the same style.

if you were to set your class to be:
<Style ref=&quot;stylesheet&quot; type=&quot;text/css&quot;>
<!--
Input{ background-color:#FFFFCC;
color:#996633;
width:100px;
Height:20px;
}
-->
</Style>

Then all of the buttons on the page would look the way your css dictates. Since this is input though, anything else deemed as an input control would be effected, so this may have some adverse effects. Gotta be a way to set the button column though...I'm thinking of trying out a template column next, which for sure would do the trick.

hth

D'Arcy
 
D'Arcy!

Thanks for staying with it. I came to the same conclusion on the cssclass property (after setting the cell background to blue a few times).

I've been digging around every source I can conjur up. There are over 100 post on one site and about 50 on another. I finally, in desperation, did a plain old goodle search of buttoncolumn and found another Gillion listings. I finally came across this article by Scott Mitchell that made enough sense to use.


Basically, it uses the datagrid's OnItemCreated event to call a sub to set the style of the button.

here is the if statement form the OnItemCreated event handler:

If e.Item.ItemType = ListItemType.Item OR _
e.Item.ItemType = ListItemType.AlternatingItem then

Dim myButton as Button = CType(e.Item.Cells(4).Controls(0), Button)
myButton.CssClass = &quot;colbutton&quot;
End If

I tried it and it worked perfectly, pulling in all the style attributes I had set in the colbutton stylesheet.

Maybe you can use it sometime.

Thanks for the help.

Tom T
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top