Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to set button click if id is set dynamicly

Posted on 2013-01-04
1
Medium Priority
?
223 Views
Last Modified: 2013-01-22
Hello,

I have set a list of link buttons dynamically (shown below)

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim dtholidays As New DataTable()
        dtholidays = dateallreadybooked.getusers()
        Dim myhols As DataView
        myhols = New DataView(dtholidays, "", "", DataViewRowState.CurrentRows)

        For Each Dayitis In myhols

            Dim linkbutton As New LinkButton
            linkbutton.Text = Dayitis.Item("FirstName") & " " & Dayitis.Item("Surename")
            linkbutton.ID = Dayitis.Item("Surename")
            Dim newline As String = Environment.NewLine
            holder.Controls.Add(linkbutton)
            Dim spacer As New System.Web.UI.WebControls.Label
            spacer.Text = "<br />"
            holder.Controls.Add(spacer)
        Next
    End Sub

Open in new window


how could i set the onlcick method so its basiclylike the below


  Protected Sub Dayitis.Item("FirstName")_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Dayitis.Item("FirstName").Click

    End Sub

Open in new window

0
Comment
Question by:runnerjp2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 18

Accepted Solution

by:
Rajar Ahmed earned 2000 total points
ID: 38744373
Try this,
Imports System.Data

Partial Class dynamicControl
    Inherits System.Web.UI.Page
    Private Shared Function GetTable() As DataTable
        Dim table As New DataTable()
        table.Columns.Add("id", GetType(Integer))
        table.Columns.Add("name", GetType(String))

        table.Rows.Add(25, "Indocin")
        table.Rows.Add(50, "Enebrel")
        table.Rows.Add(10, "Hydralazine")
        table.Rows.Add(21, "Combivent")
        table.Rows.Add(100, "Dilantin")
        Return table
    End Function
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim dtholidays As New DataTable()
        dtholidays = GetTable()
        Dim myhols As DataView
        myhols = New DataView(dtholidays, "", "", DataViewRowState.CurrentRows)
        For Each Dayitis In myhols
            Dim linkbutton As New LinkButton
            linkbutton.Text = Dayitis.Item("name") & " " & Dayitis.Item("id")
            linkbutton.CommandName = Dayitis.Item("name")
            linkbutton.ID = Dayitis.Item("name") & Dayitis.Item("id")
            AddHandler linkbutton.Click, AddressOf dynamic_Link_Click
            Dim newline As String = Environment.NewLine
            form1.Controls.Add(linkbutton)
            Dim spacer As New System.Web.UI.WebControls.Label
            spacer.Text = "<br />"
            form1.Controls.Add(spacer)
        Next
    End Sub

    Protected Sub dynamic_Link_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim lnkBtn As LinkButton = TryCast(sender, LinkButton)
        Response.Write("You have clicked " & lnkBtn.ID & " Button")
    End Sub
End Class

Open in new window

0

Featured Post

Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

705 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