Html的Table和它的行转变成服务器控件的
方法,及动态
生成n个列后对列的访问 Dim TableNameStr As String = Me.TB_TableName.Text myT = TData( DataSource/LiuLi_FST.mdb,TableNameStr) ShowRowCounts = myT.Rows.Count ShowColCounts = myT.Columns.Count 定义一个Html的行和列 Dim myr As HtmlTableRow Dim myc As HtmlTableCell 定义1个Html的行,但是没有用到它,因为使用了表自身的行控件:TableOperationRow myr = New HtmlTableRow 定义ShowColCounts-2个Html的列 For i As Integer = 1 To ShowColCounts - 1 myc = New HtmlTableCell myc.InnerHtml = zzmdegm 使用表自身的行控件 TableOperationRow.Cells.Add(myc) Next TableOperation.Rows.Add(myr) 注:如果发现定义了runat= server 后在
后台不能得到Html控件,那么保存、把本
页面关闭再重新打开后就可以使用了 __________________________________________________________________________ 对列的访问: TableOperation.Rows(0).Cells(0).InnerHtml = 这样就访问了! __________________________________________________________________________ 上面的还不能访问。因为在
页面动态
生成没有返回到服务器。服务器端只有第0行的第0列。 要把
生成后的表给一个
全局变量就行了。 下面为
代码: Public myHtmlTable As System.Web.UI.HtmlControls.HtmlTable Private Sub Page_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load 在此处放置初始化页的
用户代码 Dim
sqlConStr As String = server=(local);database=GM_B225;Uid=sa;Pwd=shuangwei_2004 Dim con As New
sqlConnection(
sqlConStr) Dim myT As New DataTable Dim com As New
sqlCommand( select * from TPageNews,con) Dim ada As New
sqlDataAdapter(com) ada.Fill(myT) Dim ShowRowCounts As Integer = myT.Rows.Count Dim ShowColCounts As Integer = myT.Columns.Count 定义一个Html的行和列 Dim myr As HtmlTableRow Dim myc As HtmlTableCell 定义1个Html的行,但是没有用到它,因为使用了表自身的行控件:TableOperationRow For j As Integer = 0 To ShowRowCounts - 1 myr = New HtmlTableRow 定义ShowColCounts-2个Html的列 For i As Integer = 1 To ShowColCounts - 1 myc = New HtmlTableCell myc.InnerHtml = myT.Rows(j).Item(i).ToString() 使用表自身的行控件 myr.Cells.Add(myc) Next TableOperation.Rows.Add(myr) Next myHtmlTable = TableOperation End Sub Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click Dim s As String = myHtmlTable.Rows(0).Cells(1).InnerHtml Dim myCountRow As Integer = myHtmlTable.Rows.Count Dim myCountCol As Integer = myHtmlTable.Rows(0).Cells.Count End Sub __________________________________________________________________________
原文链接:https://www.f2er.com/vb/263669.html