Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Greetings to you all

I have this table in asp.net and i`m creating dynamic rows for certain data of specific user, and I`m creating dynamic buttons for each row.

I want to store each ID the of each row of the data in the button ID property of the button (because there is no tag property) but because of the dynamic button, I can`t see it from the procedure I create for handling the button.

now I cant send any parameters using Addhandler command or any thing and i`ve tried many ideas online for solving this problem with no avail.

here is the significant part of my code


VB
For I = 0 To DT.Rows.Count - 1
            Dim TR As New TableRow
            If I Mod 2 <> 0 Then
                TR.BackColor = Color.Gray
                TR.ForeColor = Color.White
            Else
                TR.BackColor = Color.White
                TR.ForeColor = Color.Black
            End If

            TC = New TableCell
            TC.HorizontalAlign = HorizontalAlign.Center
            Dim b As New Button
            b.Text = &quot;اجابة&quot;
            b.Width = 40

            b.ID = DT.Rows(I).Item(&quot;ID&quot;)
            AddHandler b.Click, AddressOf DynButton_Click


            TC.Controls.Add(b)
            TC.Width = 40
            TR.Cells.Add(TC)
            Next


VB
Private Sub DynButton_Click(ByVal sender As Object, ByVal e As EventArgs)
        MsgBox(b.ID)
    End Sub
Posted

1 solution

Um...you did notice the sender parameter?
Cast the sender as a Button, and you should be able to access the ID property for the specific button that was clicked.
 
Share this answer
 
Comments
Ali Albasri 9-Jan-15 4:37am    
Seems promising ... tomorrow morning I will give it a try
thanks a lot OriginalGriff
OriginalGriff 9-Jan-15 5:19am    
You're welcome!
Ali Albasri 10-Jan-15 4:42am    
It worked Smoothly, Thanks man
OriginalGriff 10-Jan-15 4:46am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900