[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Cast LiteralControl to WebControls.button

Posted on 2006-03-28
9
Medium Priority
?
841 Views
Last Modified: 2007-12-19
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.GridViewRowEventArgs) 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.Item(0), Button)
               
                btnPrice.Attributes.Add("OnMouseOver", "this.style.cursor='hand';this.style.border='Outset';style.borderWidth='2'")
                btnPrice.Attributes.Add("OnMouseOut", "this.style.cursor='default';this.style.border='Solid'; style.borderWidth='1'")
            Next
        End Sub
0
Comment
Question by:lyntron4545
  • 5
  • 4
9 Comments
 
LVL 5

Accepted Solution

by:
Darth_helge earned 2000 total points
ID: 16318681
try this
Protected Sub dgvPartPrice_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles dgvPartPrice.RowDataBound
                Dim btnPrice As Button = CType(e.Row.FindControl("txtMyButtonName"), Button)
               
                btnPrice.Attributes.Add("OnMouseOver", "this.style.cursor='hand';this.style.border='Outset';style.borderWidth='2'")
                btnPrice.Attributes.Add("OnMouseOut", "this.style.cursor='default';this.style.border='Solid'; style.borderWidth='1'")
        End Sub

because this event is fired each time a row has been databound you dont need to loop through all the rows in this event.
0
 

Author Comment

by:lyntron4545
ID: 16318741
Thanks for the reply
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
0
 
LVL 5

Expert Comment

by:Darth_helge
ID: 16318788
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("btnPrice"), Button)

gridview sorts out which button to fetch because he knows which row he is on
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:lyntron4545
ID: 16321891
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
0
 
LVL 5

Expert Comment

by:Darth_helge
ID: 16329465
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
0
 

Author Comment

by:lyntron4545
ID: 16334678
Thanks-
I wish I could give you extra points!!!
0
 
LVL 5

Expert Comment

by:Darth_helge
ID: 16340122
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 :=)
0
 
LVL 5

Expert Comment

by:Darth_helge
ID: 16340127
just referring to the last question in this thread :=)
0
 

Author Comment

by:lyntron4545
ID: 16344959
Search for "Page level events - Darth_helge" and claim your points.  Thanks again!!!!

LT
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question