在动态生成的html表中处理Linkbutton事件 [英] Handling Linkbutton event in dynamically generated html table
本文介绍了在动态生成的html表中处理Linkbutton事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的,
查找下面的代码
Dim hTable 作为 新 HtmlTable()
私人 Sub makeHTML( ByVal pDataSet As DataSet)
Dim lRowCount 作为 整数 = 0
Dim lColCount As 整数 = 0
Dim hCell( 23 )< span class =code-keyword> As HtmlTableCell
Dim lHyperLink(pDataSet.Tables( 0 )。Rows.Count)作为 LinkButton
而 lRowCount< pDataSet.Tables( 0 )。Rows.Count
Dim hRow 作为 新 HtmlTableRow
lHyperLink(lRowCount)= 新 LinkButton()
lHyperLink(lRowCount).Text = Hello
lHyperLink(lRowCount).ID = LBHLink + lRowCount.ToString
AddHandler lHyperLink(lRowCount)。点击, AddressOf lHyperLink_Click
hCell(lColCount).Controls.Add(lHyperLink(lRowCount))
lRowCount + = 1
结束 while
hTable.Rows.Add(hRow)
TblPanel.Controls.Add(hTable)
结束 Sub
受保护 Sub lHyperLink_Click( ByVal sender As 对象, ByVal e As System.EventArgs)
' 此处处理的事件操作
结束 Sub
事件处理程序不是被叫。
请帮忙。
解决方案
如果稍作修改,它现在应该如下所示。
私人 Sub makeHTML( ByVal pDataSet As DataSet)
Dim lRowCount As 整数 = 0
Dim lColCount 作为 整数 = 0
Dim hCell As 新 HtmlTableCell
Dim lHyperLink(pDataSet.Tables( 0 )。Rows.Count) 作为 LinkButton
lRowCount< pDataSet.Tables( 0 )。Rows.Count
Dim hRow As 新 HtmlTableRow
hRow.Cells.Add(hCell)
lHyperLink (lRowCount)= 新 LinkButton()
lHyperLink(lRowCount).Text = Hello
lHyperLink(lRowCount).ID = LBHLink + lRowCount.ToString
AddHandler lHyperLink(lRowCount)。点击, AddressOf lHyperLink_Click
hRow.Cells(lColCount).Controls.Add(lHyperLink(lRowCount))
lRowCount + = 1
hTable.Rows.Add(hRow)
结束 虽然
tPanel.Con trols.Add(hTable)
结束 Sub
Dear All,
Find my code below
Dim hTable As New HtmlTable()
Private Sub makeHTML(ByVal pDataSet As DataSet)
Dim lRowCount As Integer = 0
Dim lColCount As Integer = 0
Dim hCell(23) As HtmlTableCell
Dim lHyperLink(pDataSet.Tables(0).Rows.Count) As LinkButton
While lRowCount < pDataSet.Tables(0).Rows.Count
Dim hRow As New HtmlTableRow
lHyperLink(lRowCount) = New LinkButton()
lHyperLink(lRowCount).Text = "Hello"
lHyperLink(lRowCount).ID = "LBHLink" + lRowCount.ToString
AddHandler lHyperLink(lRowCount).Click, AddressOf lHyperLink_Click
hCell(lColCount).Controls.Add(lHyperLink(lRowCount))
lRowCount += 1
End While
hTable.Rows.Add(hRow)
TblPanel.Controls.Add(hTable)
End Sub
Protected Sub lHyperLink_Click(ByVal sender As Object, ByVal e As System.EventArgs)
' Handled event actions here
End Sub
Event handler is not getting called.
Kindly help.
解决方案
Hi,
With little modification it should work now as below.
Private Sub makeHTML(ByVal pDataSet As DataSet) Dim lRowCount As Integer = 0 Dim lColCount As Integer = 0 Dim hCell As New HtmlTableCell Dim lHyperLink(pDataSet.Tables(0).Rows.Count) As LinkButton While lRowCount < pDataSet.Tables(0).Rows.Count Dim hRow As New HtmlTableRow hRow.Cells.Add(hCell) lHyperLink(lRowCount) = New LinkButton() lHyperLink(lRowCount).Text = "Hello" lHyperLink(lRowCount).ID = "LBHLink" + lRowCount.ToString AddHandler lHyperLink(lRowCount).Click, AddressOf lHyperLink_Click hRow.Cells(lColCount).Controls.Add(lHyperLink(lRowCount)) lRowCount += 1 hTable.Rows.Add(hRow) End While tPanel.Controls.Add(hTable) End Sub
这篇关于在动态生成的html表中处理Linkbutton事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文