Handling Dynamic Image buttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vamshiv
    New Member
    • Jun 2007
    • 3

    #1

    Handling Dynamic Image buttons

    hi...im working on asp.net with VB
    i have created a database which hav fields id,name,image path
    in web form i hav written code for creation of image buttons dynamically
    i hav connected the form to DB and got the table into DataSet

    and also i hav placed one panel which contains image and label controls

    for dynamic image buttons i hav given the image URL from table only. and i hav written addHandler method to hanling events

    But for every button it handling one event only....

    when i click the image button which r developed dynamically.... .the panel shld show the details of that imagebutton.

    ---------------------------------------------------------------------------

    Imports System.Data
    Imports System.Data.Sql Client
    Imports System.Web.UI.C ontrol
    .
    Partial Class Default2
    Inherits System.Web.UI.P age

    Dim con As New SqlConnection
    Dim da As SqlClient.SqlDa taAdapter
    Dim strSQL As String
    Dim ds As New DataSet
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load
    con = New SqlConnection(" Data Source=SYSTEM23 \SQLEXPRESS;Ini tial Catalog=epo;Int egrated Security=True")
    strSQL = "select * from details"
    da = New SqlClient.SqlDa taAdapter(strSQ L, con)
    da.Fill(ds, "details")
    Dim i As Int16
    Dim j As Int16
    Dim counter As Int16 = 0

    i = ds.Tables("deta ils").Rows.Coun t.ToString

    For j = 0 To i - 1

    Dim img As New ImageButton
    img.ID = "imageButto n" & j


    PlaceHolder1.Co ntrols.Add(img)
    img.Visible = True
    img.ImageUrl = ds.Tables("deta ils").Rows(j)(2 )
    img.Width = 200
    img.Height = 200
    AddHandler img.Command, AddressOf method1

    '-- Add a pair of blank spaces

    Dim MySpace As New Literal
    MySpace.Text = "  &n bsp; &nbsp ; "
    PlaceHolder1.Co ntrols.Add(MySp ace)

    '-- Add a line break
    Counter += 1
    If counter Mod 4 = 0 Then
    Dim MyBreak As New Literal
    MyBreak.Text = "<br/>"
    PlaceHolder1.Co ntrols.Add(MyBr eak)

    End If

    Next


    End Sub
    Private Sub method1(ByVal Src As Object, ByVal Args As CommandEventArg s)

    Panel1.Visible = True

    End Sub
  • dip_developer
    Recognized Expert Contributor
    • Aug 2006
    • 648

    #2
    Originally posted by vamshiv
    hi...im working on asp.net with VB
    i have created a database which hav fields id,name,image path
    in web form i hav written code for creation of image buttons dynamically
    i hav connected the form to DB and got the table into DataSet

    and also i hav placed one panel which contains image and label controls

    for dynamic image buttons i hav given the image URL from table only. and i hav written addHandler method to hanling events

    But for every button it handling one event only....

    when i click the image button which r developed dynamically.... .the panel shld show the details of that imagebutton.

    ---------------------------------------------------------------------------

    Imports System.Data
    Imports System.Data.Sql Client
    Imports System.Web.UI.C ontrol
    .
    Partial Class Default2
    Inherits System.Web.UI.P age

    Dim con As New SqlConnection
    Dim da As SqlClient.SqlDa taAdapter
    Dim strSQL As String
    Dim ds As New DataSet
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load
    con = New SqlConnection(" Data Source=SYSTEM23 \SQLEXPRESS;Ini tial Catalog=epo;Int egrated Security=True")
    strSQL = "select * from details"
    da = New SqlClient.SqlDa taAdapter(strSQ L, con)
    da.Fill(ds, "details")
    Dim i As Int16
    Dim j As Int16
    Dim counter As Int16 = 0

    i = ds.Tables("deta ils").Rows.Coun t.ToString

    For j = 0 To i - 1

    Dim img As New ImageButton
    img.ID = "imageButto n" & j


    PlaceHolder1.Co ntrols.Add(img)
    img.Visible = True
    img.ImageUrl = ds.Tables("deta ils").Rows(j)(2 )
    img.Width = 200
    img.Height = 200
    AddHandler img.Command, AddressOf method1

    '-- Add a pair of blank spaces

    Dim MySpace As New Literal
    MySpace.Text = "&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;"
    PlaceHolder1.Co ntrols.Add(MySp ace)

    '-- Add a line break
    Counter += 1
    If counter Mod 4 = 0 Then
    Dim MyBreak As New Literal
    MyBreak.Text = "<br/>"
    PlaceHolder1.Co ntrols.Add(MyBr eak)

    End If

    Next


    End Sub
    Private Sub method1(ByVal Src As Object, ByVal Args As CommandEventArg s)

    Panel1.Visible = True

    End Sub
    So whats the problem?????... .You have created one Eventhandler for every button.....this event will cause method1 to be executed in every button's click....you can have the button's id ,which causing the event to fire,inside method1 and do the needful.

    Comment

    • kenobewan
      Recognized Expert Specialist
      • Dec 2006
      • 4871

      #3
      Your eventhandler can call one function which in turn call another.

      Comment

      • vamshiv
        New Member
        • Jun 2007
        • 3

        #4
        ACTUALLY I WANT TO GET THE DETAILS OF PRODUCT FROM DataSet TO THE PANEL.......THI S DETAILS DEPENDS ON THE WHICH IMAGE BUTTON WE HAV CLICKED ........
        SAMPLE WEB PAGE:

        http://search.live.com/images/results.aspx?q= nokia&FORM=QBIR

        c the above link....u can get some idea

        if i run my prog i will get the page like above

        if i click on any image button the selected image details should be come to panel.....

        Plz help me in this

        if u give mail address...i will send this project also

        Comment

        • vamshiv
          New Member
          • Jun 2007
          • 3

          #5
          Plzz help me in this..........

          Comment

          Working...