ASP.NET (vb) Adding LinkButtons Dynamically

liunx

Guest
I'm adding a serires of linkbuttons based on database rows. Two questions. First, is the linkbutton.CommandArgument the appropiate property to use to assign a value to the link button? I need to match the button with the database row key id. Second, how do you assign an on_click event? The way I have it does not work:


While myMemberListDtr.Read()
Dim LnkBtn As New LinkButton()
plhPlaceHolder.Controls.Add( New LiteralControl( "<td>))
LnkBtn.Text = myMemberListDtr("lname") & ", " & myMemberListDtr("fname")
LnkBtn.CommandArgument = myMemberListDtr("mem_id")
LnkBtn.OnClick = linkbutton_click
plhPlaceHolder.Controls.Add(LnkBtn)
plhPlaceHolder.Controls.Add( New LiteralControl( "</a></td>" ))
End While

Thanks!!!

CaseyWhy exactly do you need a link button? What are you trying to do (big picture). I have found that I never have used the link button... I have used a regular link with a query string to carry variables from page to page and fired scripts on the next page based on the value of the query string. Link buttons seem to be javascript dependent, which is a major turn off to me.Hi,

I can answer one of your questions.
You add an event handler to a control in this way:

1. First you declare your variable as a class variable, not local to a procedure, and you declare it with the WithEvents option

Protected WithEvents LnkBtn as New LinkButton

2. Then you add this line of code to add the Click event

AddHandler .Click, AddressOf LinkButton_Click

3. LinkButton_Click is the procedure that you write to handle the click event.

Good Luck!

Happy New Year!
 
Back
Top