Actually i am trying to find the author of the article in this link.
http://authors.aspalliance.com/articles/dynamicbuttons.aspx

But i failed as the provided email address is invalid.

So i hope here can find the solution for it. Here it goes from the article exempted source code show on below
--------------------------------

Sub Page_Load (Sender As Object, e As EventArgs)
     CreateDynamicButtons()
End Sub

Sub CreateDynamicButtons () 

     'Get database information into my user-defined server control called database
     '... 
     'End database information

     dim lbLink as LinkButton 
     dim dbRow as System.Data.DataRow

     for each dbRow in database.table("tablename").rows 
          lbLink = new LinkButton lbLink.Text = dbrow.item("categoryname") 
          lbLink.CommandName = "CategoryId" 
          lbLink.CommandArgument = dbrow.item("CategoryId") 
          AddHandler lbLink.Command, AddressOf lbLink_Click
          pnlSelectCategoryl.Controls.Add(lbLink)
     next 
End Sub

Sub ChooseCategory (Sender As Object, e as EventArgs) 
     pnlSelectCategory.visible = true 
     pnlSelectItem.visible = false 
     pnlViewItem.visible = false 
     pnlViewCart.visible = false 
     pnlCheckout.visible = false 
     pnlOrderPlaced.visible = false 
End Sub

Sub lbLink_Click (Sender As Object, e As CommandEventArgs) 
     dim lbLink As LinkButton = CType(Sender, LinkButton) 
     dim CategoryId as String = lbLink.CommandArgument 
     ' Do things with this information
     '...
End Sub

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


I found it is very useful to guide me for my final year project.
Below is a part of the source code, that i have some question to ask
you. I want to know what is the type for 'database' as
the article you posted doest not provide the declaration.

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

For Each dbRow In database.table("tablename").rows
lbLink = new LinkButton lbLink.Text = dbrow.item("categoryname")

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

I also understand that the question might not be answer, so i also want to state out here the real problem i want to solve here

I am very appreciate if you can provide more example to show me on how to manipulate the use of dynamic button.
Below is the project i am working with. I am trying to build application that enable user to book seat by click of a button. The button will display the seat id and also will appear in Green for availability and Red in vise versa.

But i don't not know how to create the function for the dynamic button when it is clicked. I hope you can provide me some guidance. Below is my source code.
--------------------------------------------------

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
 
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\KELVINTEOH\Desktop\Boon Foo Websites\PSM\App_Data\PSM.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
Dim strselect As String
 
 
strselect = "SELECT Lot.LotID AS LotID, Lot.BlockID, Property.AvailableStatus AS Status From Lot INNER JOIN Property ON Lot.PID = Property.PropertyID"
 
 


Dim myCommand As New SqlCommand(strselect, con)
con.Open()
Dim myReader As SqlDataReader = myCommand.ExecuteReader
 
 
Dim tableLayoutPlan As New Table()
tableLayoutPlan.ID = "tblLayout"
tableLayoutPlan.BorderWidth = 1
PlaceHolder1.Controls.Add(tableLayoutPlan)
 
 

Dim kounter As Integer = 3
While kounter > 1
Dim row As New TableRow
For ReadLot As Integer = 1 To 2
myReader.Read()
Dim LotName As String
Dim Status As String
Dim cell As New TableCell
Dim Lot As New Button()
LotName = myReader("LotID")
Status = myReader("Status")
Lot.ID = "btn" + LotName
Lot.Text = LotName
 

If Status = "Available" Then
Lot.BackColor = Drawing.Color.DarkGreen
Else
Lot.BackColor = Drawing.Color.DarkRed
End If
 
 
 
cell.Controls.Add(Lot)
row.Cells.Add(cell)
Next
tableLayoutPlan.Rows.Add(row)
 
 
kounter = kounter - 1
End While
 
myReader.Close()
con.Close()
End Sub

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

>But i don't not know how to create the function for the dynamic button when it is clicked.

Try this,

protected void Page_Load(object sender, EventArgs e)
    {
        int i = 0;
        if (Request["Button1"] != null)
        {

            if (Session["btn"] != null)
            {
                i = int.Parse(Session["btn"].ToString());
                i++;
                Session["btn"] = i;
            }
            else
            {
                i = 1;
                Session["btn"] = i;
            }
        }
        else
        {
            if (Session["btn"] == null)
                i = 0;
            else
                i = int.Parse(Session["btn"].ToString());
        }

        for (int c = 0; c < i; c++)
        {
            Button b1 = new Button();
            b1.Text = "New Button";
            b1.CommandArgument = c.ToString();
            b1.Command += new CommandEventHandler(b1_Command);
            form1.Controls.Add(b1);
        }
    }

    void b1_Command(object sender, CommandEventArgs e)
    {
        Response.Write(e.CommandArgument.ToString());
    }

VB.NET

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim i As Integer = 0
    If Request("Button1") IsNot Nothing Then
        
        If Session("btn") IsNot Nothing Then
            i = Integer.Parse(Session("btn").ToString())
            i += 1
            Session("btn") = i
        Else
            i = 1
            Session("btn") = i
        End If
    Else
        If Session("btn") Is Nothing Then
            i = 0
        Else
            i = Integer.Parse(Session("btn").ToString())
        End If
    End If
    
    For c As Integer = 0 To i - 1
        Dim b1 As New Button()
        b1.Text = "New Button"
        b1.CommandArgument = c.ToString()
        AddHandler b1.Command, AddressOf b1_Command
        form1.Controls.Add(b1)
    Next
End Sub

Private Sub b1_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
        
    Response.Write(e.CommandArgument.ToString())
End Sub

Hi

You can refer following code.i will give you code for ASP NET Dynamic Buttons Event Handler‏.it will help you.

 public partial class Database_DbOrderview : System.Web.UI.Page
{
    public SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Mydbcs"].ConnectionString);
    SqlDataAdapter adp = new SqlDataAdapter("", "");
    SqlCommandBuilder cbi = new SqlCommandBuilder();
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
          if (RadioButtonList1.SelectedValue == "Date")
          {
              DateDynamicTable();
          }
    }

    private void DateDynamicTable()
    {
        PlaceHolder1.Controls.Clear();

        //Create New Table

        Table DateTable = new Table();
        DateTable.BorderWidth = 0;
        DateTable.CellSpacing = 10;
        DateTable.Style["Font-Size"] = "Small";
        PlaceHolder1.Controls.Add(DateTable);

        //Add Rows and Columns in Table

        TableRow tr1 = new TableRow();

        TableCell tc11 = new TableCell();
        Label DateFromlabel = new Label();
        DateFromlabel.Text = "From :";
        tc11.Controls.Add(DateFromlabel);

        TableCell tc12 = new TableCell();
        TextBox DateFromtxtbox = new TextBox();
        DateFromtxtbox.ID = "DateFromtxtbox";
        AjaxControlToolkit.CalendarExtender calEx1 = new AjaxControlToolkit.CalendarExtender();
        calEx1.TargetControlID = "DateFromtxtbox";
        tc12.Controls.Add(DateFromtxtbox);
        tc12.Controls.Add(calEx1);

        TableCell tc13 = new TableCell();
        Label DateTolabel = new Label();
        DateTolabel.Text = "To :";
        tc13.Controls.Add(DateTolabel);

        TableCell tc14 = new TableCell();
        TextBox DateTotxtbox = new TextBox();
        DateTotxtbox.ID = "DateTotxtbox";
        AjaxControlToolkit.CalendarExtender calEx2 = new AjaxControlToolkit.CalendarExtender();
        calEx2.TargetControlID = "DateTotxtbox";
        tc14.Controls.Add(DateTotxtbox);
        tc14.Controls.Add(calEx2);

        tr1.Controls.Add(tc11);
        tr1.Controls.Add(tc12);
        tr1.Controls.Add(tc13);
        tr1.Controls.Add(tc14);

        TableRow tr2 = new TableRow();
        TableCell tc21 = new TableCell();
        Button ViewDatebtn = new Button();
        ViewDatebtn.ID = "Viewbtn";
        ViewDatebtn.Text = "View";
        ViewDatebtn.Click += new EventHandler(ViewDatebtn_Click);
        tc21.Controls.Add(ViewDatebtn);

        tr2.Controls.Add(tc21);

        DateTable.Controls.Add(tr1);
        DateTable.Controls.Add(tr2);
    }

    void ViewDatebtn_Click(object sender, EventArgs e)
    {
        //throw new NotImplementedException();
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.