Solved

how to set button click if id is set dynamicly

Posted on 2013-01-04
1
215 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 500 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

624 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