How to dynamically disable GridView's alternaterowstyle?

G

gnewsgroup

I am creating GridView(s) on the fly and add them to a PlaceHolder
control. The skin file of my application orders GridViews to have an
alternate row style.

But on this particular aspx page, I do NOT want alternate row style
for GridView(s). In other words, I want it plain white with grid
lines.

I tried setting Theme and StylesheetTheme to empty strings in the page
directive, but then my page header and footer all lost the pre-defined
styles.

I was hoping that I could do something like

myDynamicGridView.EnableAlternateRowStyle = false;

But, of course there is no such thing as EnableAlternateRowStyle.

So, how do I disable alternate row style? Thank you.
 
A

Angel

I've been grapping about this sort of thing for a while. This is the problem
you find your self in when you rely too much on the declarative model.

I tried what I think you were describing and was able to easily alternate
between plain and alternate. My choice of colors sucks but it gets the point
across

For demo:

Two buttons

Protected Sub Button1_click (ByVal Sender As Object, ByVal e as
system.eventArgs) handles button1.Click

Gridview1.AlternatingRowStyle.BackColor = Drawing.color.Gainsboro
Gridview1.AlternatingRowStyle.ForeColor = Drawing.color.White
Gridview1.DataBind()

End Sub

Protected Sub Button1_click (ByVal Sender As Object, ByVal e as
system.eventArgs) handles button1.Click
Gridview1.AlternatingRowStyle.BackColor = Gridview1.RowStyle.BaclColor
Gridview1.AlternatingRowStyle.ForeColor = Gridview1.RowStyle.ForeColor
Gridview1.DataBind()
End Sub

the Gridview1.DataBind may not be needed it depends on how you have
viewstate setup and other factors. It would not be difficult to replace the
button with logic

hope it helps
 
G

gnewsgroup

I've been grapping about this sort of thing for a while. This is the problem
you find your self in when you rely too much on the declarative model.

I tried what I think you were describing and was able to easily alternate
between plain and alternate.  My choice of colors sucks but it gets the point
across

For demo:  

Two buttons

Protected Sub Button1_click (ByVal Sender As Object, ByVal e as
system.eventArgs) handles button1.Click

Gridview1.AlternatingRowStyle.BackColor = Drawing.color.Gainsboro
        Gridview1.AlternatingRowStyle.ForeColor = Drawing.color.White
        Gridview1.DataBind()

End Sub

Protected Sub Button1_click (ByVal Sender As Object, ByVal e as
system.eventArgs) handles button1.Click
Gridview1.AlternatingRowStyle.BackColor = Gridview1.RowStyle.BaclColor
        Gridview1.AlternatingRowStyle.ForeColor = Gridview1.RowStyle.ForeColor
        Gridview1.DataBind()
End Sub

the Gridview1.DataBind may not be needed it depends on how you have
viewstate setup and other factors.  It would not be difficult to replace the
button with logic

hope it helps
--
aaa











- Show quoted text -

Thank you very much. But, I think I said that I do NOT want alternate
row style. I want to dynamically disable alternate row style.
 
L

Larry Bud

Thank you very much.  But, I think I said that I do NOT want alternate
row style.   I want to dynamically disable alternate row style

Why don't you just make it the same style as the regular row?
 
A

Angel

The way you can disable the alternate rowstyle is by making it the same as
the RowStyle. I gave you that example in the second button. I gave a code
example because you said that you wanted to do this dynamically.

GridView1.AlternatingRowStyle.ForeColor = GridView1.RowTyle.forecolor
GridView1.AlternatingRowStyle.backColor = GridView1.RowTyle.backcolor

or the only things that changes and by setting it to the same value you get
rid of it.

if you are looking for something like
GridView1.AlternatingRowStyle.Disabled =true?! I don't think we have that.


aaa
 
G

gnewsgroup

The way you can disable the alternate rowstyle is by making it the same as
the RowStyle.  I gave you that example in the second button. I gave a code
example because you said that you wanted to do this dynamically.  

GridView1.AlternatingRowStyle.ForeColor = GridView1.RowTyle.forecolor
GridView1.AlternatingRowStyle.backColor = GridView1.RowTyle.backcolor

or the only things that changes and by setting it to the same value you get
rid of it.

if you are looking for something like
GridView1.AlternatingRowStyle.Disabled =true?! I don't think we have that.

aaa






- Show quoted text -

I think tried what you said as this:

GridView1.AlternatingRowStyle.ForeColor = GridView1.RowTyle.forecolor
GridView1.AlternatingRowStyle.backColor = GridView1.RowTyle.backcolor

But, it did not seem to work.
 
A

Angel

I have a grid with the buttons I showed you before and it works fine. The
buttons can be replaced with whatever logic you like. You must make sure
this is being done at the right time in the page life cycle otherwise it
might not work.

The page load event or right after that is safe.
 
D

Dave Sussman

Create another entry in your skin file, copying the current declaration for
the GridView. Then change the AlternatingRowStyle to the same as the
RowStyle, and add a SkinID (eg Skin="RowsTheSame") to the declaration of the
GridView in the skin. Set the same SkinID on the control on the page. This
will ensure this instance of the GridView uses the skin matched by the
SkinID, rather than the default in the skin.

Dave
 
G

gnewsgroup

Create another entry in your skin file, copying the current declaration for
the GridView. Then change the AlternatingRowStyle to the same as the
RowStyle, and add a SkinID (eg Skin="RowsTheSame") to the declaration of the
GridView in the skin. Set the same SkinID on the control on the page. This
will ensure this instance of the GridView uses the skin matched by the
SkinID, rather than the default in the skin.

Dave

Thanks, the problem is that the gridviews are created on the fly in my
code-behind and added to a placeholder control.
 
D

Dave Sussman

In that case just set the SkinID on the GridView when created in code.

d

Create another entry in your skin file, copying the current declaration
for
the GridView. Then change the AlternatingRowStyle to the same as the
RowStyle, and add a SkinID (eg Skin="RowsTheSame") to the declaration of
the
GridView in the skin. Set the same SkinID on the control on the page. This
will ensure this instance of the GridView uses the skin matched by the
SkinID, rather than the default in the skin.

Dave

Thanks, the problem is that the gridviews are created on the fly in my
code-behind and added to a placeholder control.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top