lyntron4545
asked on
Cast LiteralControl to WebControls.button
Is there any way to add attributes to a template button in a gridview. I've tried to Ctype the control in the column but it gives me an invalid cast expection. What I'm trying to do is add rollover effects thru a codebehind page. Any ideas?
Code:
Protected Sub dgvPartPrice_RowDataBound( ByVal sender As Object, ByVal e As System.Web.UI.WebControls. GridViewRo wEventArgs ) Handles dgvPartPrice.RowDataBound
Static intRowCounter As Integer = 0
Dim i As Integer
For i = 0 To dgvPartPrice.Rows.Count - 1
Dim btnPrice As Button = CType(dgvPartPrice.Rows(i) .Cells(0). Controls.I tem(0), Button)
btnPrice.Attributes.Add("O nMouseOver ", "this.style.cursor='hand'; this.style .border='O utset';sty le.borderW idth='2'")
btnPrice.Attributes.Add("O nMouseOut" , "this.style.cursor='defaul t';this.st yle.border ='Solid'; style.borderWidth='1'")
Next
End Sub
Code:
Protected Sub dgvPartPrice_RowDataBound(
Static intRowCounter As Integer = 0
Dim i As Integer
For i = 0 To dgvPartPrice.Rows.Count - 1
Dim btnPrice As Button = CType(dgvPartPrice.Rows(i)
btnPrice.Attributes.Add("O
btnPrice.Attributes.Add("O
Next
End Sub
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
what the btnPrice button is called at client side is uninteresting. You just call it by the server id.
If your button in the gridview is called "btnPrice" then you just do
Dim btnPrice As Button = CType(e.Row.FindControl("b tnPrice"), Button)
gridview sorts out which button to fetch because he knows which row he is on
If your button in the gridview is called "btnPrice" then you just do
Dim btnPrice As Button = CType(e.Row.FindControl("b
gridview sorts out which button to fetch because he knows which row he is on
ASKER
Darth_helge-
You were completely right!!!!! That was a simple solution I can't believe that it eluded me for so long. Thanks for your second post that makes alot of since. Say do you know of a website that shows a list of all asp events and when they fire. I can find some events. Thanks again for your help this really saved my bacon!!!!!
Thank you-
Lyntron4545
You were completely right!!!!! That was a simple solution I can't believe that it eluded me for so long. Thanks for your second post that makes alot of since. Say do you know of a website that shows a list of all asp events and when they fire. I can find some events. Thanks again for your help this really saved my bacon!!!!!
Thank you-
Lyntron4545
well i can give you one right now
http://weblogs.asp.net/jeff/archive/2004/07/04/172683.aspx
but if you want to put in master page events too i have some info here
http://xucanzhao.cnblogs.com/archive/2006/02/26/338197.html
http://weblogs.asp.net/jeff/archive/2004/07/04/172683.aspx
but if you want to put in master page events too i have some info here
http://xucanzhao.cnblogs.com/archive/2006/02/26/338197.html
ASKER
Thanks-
I wish I could give you extra points!!!
I wish I could give you extra points!!!
actually you could..
the event question is a standalone question, so you can ask a new question called 'points for darth helge' so i can insert a comment, then you accept it :=)
the event question is a standalone question, so you can ask a new question called 'points for darth helge' so i can insert a comment, then you accept it :=)
just referring to the last question in this thread :=)
ASKER
Search for "Page level events - Darth_helge" and claim your points. Thanks again!!!!
LT
LT
ASKER
I haven't tested your code yet but I should note that this gridview is within a content page. Would that cause any problems? Also, as I was debugging it appeared that the id was random or perhaps unique to the app itself. Is there any way around that? Thanks for the help and I'll let you know tomorrow about your suggestion.
Thanks-
LT