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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSS class not being applied to user control

Status
Not open for further replies.

Peppi

Programmer
Apr 9, 2001
205
CA
Hi,

I'm trying to change the CSSClass property of a row in my GridView control. The GridView is part of a user control.
However, the style is not being applied to the page. If I set the backcolor manually in the same section of code, that gets applied without issue.

<code>
If row.RowType = DataControlRowType.DataRow Then
If row.RowState = DataControlRowState.Alternate Then
row.CssClass = "AlternatingRowStyle"
Else
row.CssClass = "RowStyle"
End If
End If
</code>

What could the problem be?
 
1. can you see the class in the html source?
2. is the proper css file linked to the page?
3. are the RowStyle and AlternatingRowStyle classes
4. properly defined in the css file?
5. are you using CSSAdapters?

if the answer to question 5 is yes you can't use GridView(Row) styling properties. You can Only use the CSSAdapterClass property to set the CSS.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hi,

My CSS class file is defined/linked properly as the user control grids are displayed with the CSS styles when the page is first loaded. It's when the user takes some action where I need to change the style that it doesn't work.

I'm pretty sure I'm not using CSSAdapters since I don't know what they are.
 
what do you mean by "action"? Select, Edit? if so then you need to account for these Row Types as well.
Code:
If row.RowType = DataControlRowType.DataRow Then
   If row.RowState = DataControlRowState.Alternate Then
      row.CssClass = "AlternatingRowStyle"
   Else if row.RowState = DataControlRowState.Normal
      row.CssClass = "RowStyle"
   else if row.RowState = DataControlRowState.Edit
      row.CssClass = "EditRowStyle"
   else if row.RowState = DataControlRowState.select
      row.CssClass = "RowStyle"
   End If
End If

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Users will never be in edit or select "mode". The rows are always open for editing. By action I mean, when they click on the save button to save grid information. I need to highlight the row if there was an update error. Regardless, that's not the problem. The problem is that
row.CssClass = "RowStyle" does not work, although the rows are displayed with that particular style when the page first loads.
 
does the gridview have viewstate enabled?
what event do you call the above code?

if we can see more of the code we may be able to find the problem.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Still haven't been able to resolve this. Could this somehow be related to the fact that my GridView is in a user control?
 
Nope. CSS is applied to rendered HTML so it has no concept of what a user control is. Try pasting the resulint HTML and CSS file here (preferably a cut down example thta replicates your problem).


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top