动态控制事件处理 [英] Dynamic Controls Event Handling
问题描述
向大家致以问候
我在asp.net中有这个表,我正在为特定用户的某些数据创建动态行,我正在创建每行的动态按钮。
我想在按钮的按钮ID属性中存储每行数据的每个ID(因为没有标签属性) )但由于动态按钮,我无法从我为处理按钮创建的程序中看到它。
现在我无法使用Addhandler命令发送任何参数或任何事情,我在网上尝试了很多想法,无法解决这个问题。
这里是我的代码的重要部分
对于 I = 0 DT.Rows.Count - 1
Dim TR As 新 TableRow
如果我 Mod 2 <> 0 然后
TR.BackColor = Color.Gray
TR.ForeColor = Color .White
Else
TR.BackColor = Color.White
TR.ForeColor = Color.Black
结束 如果
TC = 新 TableCell
TC.HorizontalAlign = HorizontalAlign.Center
Dim b As < span class =code-keyword>新按钮
b.Text =& quot;اجابة& quot;
b.Width = 40
b.ID = DT.Rows(I).Item(& quot; ID& ;)
AddHandler b.Click, AddressOf DynButton_Click
TC.Controls.Add(b)
TC.Width = 40
TR.Cells.Add(TC)
下一步
私有 Sub DynButton_Click( ByVal sender As 对象, ByVal e As EventArgs)
MsgBox(b.ID)
结束 Sub
嗯......你们id注意sender
参数?
将发件人转换为Button,你应该能够访问特定按钮的ID属性点击。
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
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 = "اجابة"
b.Width = 40
b.ID = DT.Rows(I).Item("ID")
AddHandler b.Click, AddressOf DynButton_Click
TC.Controls.Add(b)
TC.Width = 40
TR.Cells.Add(TC)
Next
Private Sub DynButton_Click(ByVal sender As Object, ByVal e As EventArgs)
MsgBox(b.ID)
End Sub
Um...you did notice thesender
parameter?
Cast the sender as a Button, and you should be able to access the ID property for the specific button that was clicked.
这篇关于动态控制事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!