asp.net toggle image
-
How to change the image of the Imagebutton by clicking on it. I wanna chanege it 4 times. Means 4 images available. default is Black image on 1st click it changed to Blue image on 2nd click Green Image on 3rd click Red image and on 4th click again black image.... Button is used in Gridview..
-
How to change the image of the Imagebutton by clicking on it. I wanna chanege it 4 times. Means 4 images available. default is Black image on 1st click it changed to Blue image on 2nd click Green Image on 3rd click Red image and on 4th click again black image.... Button is used in Gridview..
Usually at this situation, I keep hidden imagebuttons and make it visible/hide accordingly. Note: I am not sure if this is the right way to do this.
-
How to change the image of the Imagebutton by clicking on it. I wanna chanege it 4 times. Means 4 images available. default is Black image on 1st click it changed to Blue image on 2nd click Green Image on 3rd click Red image and on 4th click again black image.... Button is used in Gridview..
You Can check on each image button click event. Take a look at the algorithm below if ( button.ImageURL = [Image1URL]) then button.ImageURL = [Image2URL] Else if (button.ImageURL == [Image2URL] ) THEN button.ImageURL = [Image3URL] ELSE IF (button.ImageURL == [Image3URL] THEN button.ImageURL = [Image4URL] ELSE button.ImageURL = [Image1URL] END IF Hope this algorithm help you out..
-
You Can check on each image button click event. Take a look at the algorithm below if ( button.ImageURL = [Image1URL]) then button.ImageURL = [Image2URL] Else if (button.ImageURL == [Image2URL] ) THEN button.ImageURL = [Image3URL] ELSE IF (button.ImageURL == [Image3URL] THEN button.ImageURL = [Image4URL] ELSE button.ImageURL = [Image1URL] END IF Hope this algorithm help you out..
I tried as u said and My code is as below.. Protected Sub ImageButton2_Click1(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) For i As Integer = 0 To GridView1.Rows.Count - 1 Dim imgbutton As ImageButton = DirectCast(GridView1.Rows(i).Cells(2).Controls(0), ImageButton) If imgbutton.ImageUrl = "~/Image/Red.png" Then imgbutton.ImageUrl = "~/Image/Green.png" ElseIf imgbutton.ImageUrl = "~/Image/Green.png" Then imgbutton.ImageUrl = "~/Image/Blue.png" ElseIf imgbutton.ImageUrl = "~/Image/Blue.png" Then imgbutton.ImageUrl = "~/Image/Black.png" Else imgbutton.ImageUrl = "~/Image/Red.png" End If Next End Sub but it gives me an error like.. Specified argument was out of the range of valid values. Parameter name: index in this code line--> Dim imgbutton As ImageButton = DirectCast(GridView1.Rows(i).Cells(2).Controls(0), ImageButton) Any solution for that??
-
Usually at this situation, I keep hidden imagebuttons and make it visible/hide accordingly. Note: I am not sure if this is the right way to do this.
:) yes but it is possible only if we have only two images to toggle. But here i have 4 images.. :(
-
I tried as u said and My code is as below.. Protected Sub ImageButton2_Click1(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) For i As Integer = 0 To GridView1.Rows.Count - 1 Dim imgbutton As ImageButton = DirectCast(GridView1.Rows(i).Cells(2).Controls(0), ImageButton) If imgbutton.ImageUrl = "~/Image/Red.png" Then imgbutton.ImageUrl = "~/Image/Green.png" ElseIf imgbutton.ImageUrl = "~/Image/Green.png" Then imgbutton.ImageUrl = "~/Image/Blue.png" ElseIf imgbutton.ImageUrl = "~/Image/Blue.png" Then imgbutton.ImageUrl = "~/Image/Black.png" Else imgbutton.ImageUrl = "~/Image/Red.png" End If Next End Sub but it gives me an error like.. Specified argument was out of the range of valid values. Parameter name: index in this code line--> Dim imgbutton As ImageButton = DirectCast(GridView1.Rows(i).Cells(2).Controls(0), ImageButton) Any solution for that??
Hi
Specified argument was out of the range of valid values. Parameter name: index
the above error will occur if GridView1.Rows(i).Cells(2).Controls(0)is exceeding its range. check for the columns you have in grid, if suppose if you have only one row with 1 cell then grid you will receive the error as you mentioned. Try to use Immediate window when you are debugging and check by copying "GridView1.Rows(1).Cells(2).Controls(0)" , if it throws error reduce the row and cell index numbers. Hope this will help. thanks
-
You Can check on each image button click event. Take a look at the algorithm below if ( button.ImageURL = [Image1URL]) then button.ImageURL = [Image2URL] Else if (button.ImageURL == [Image2URL] ) THEN button.ImageURL = [Image3URL] ELSE IF (button.ImageURL == [Image3URL] THEN button.ImageURL = [Image4URL] ELSE button.ImageURL = [Image1URL] END IF Hope this algorithm help you out..
Hey thanks i tried your algo. First it gives me an error. but i solved it and its working well :)
-
Hi
Specified argument was out of the range of valid values. Parameter name: index
the above error will occur if GridView1.Rows(i).Cells(2).Controls(0)is exceeding its range. check for the columns you have in grid, if suppose if you have only one row with 1 cell then grid you will receive the error as you mentioned. Try to use Immediate window when you are debugging and check by copying "GridView1.Rows(1).Cells(2).Controls(0)" , if it throws error reduce the row and cell index numbers. Hope this will help. thanks
Thanks for Solution...
-
Hey thanks i tried your algo. First it gives me an error. but i solved it and its working well :)