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
--------------------------------------------------------------------------------