LinkButton的问题 [英] Problem with LinkButton
本文介绍了LinkButton的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨大师,
我的Blog链接有问题。下面是我的代码。
Hi Gurus,
I have a problem with my Blog linking. below is my code.
<%@ Import Namespace = "System.Data"%>
<%@ Import Namespace = "System.Data.OleDb"%>
<%@ Page Language="VB" Debug="true" ContentType="text/html" ResponseEncoding="utf-8" %>
<SCRIPT language="VB" runat="server">
' Rows property to hold the Rows in the ViewState
Protected Property Rows() As Integer
Get
If Not ViewState("Rows") Is Nothing Then
Return CInt(Fix(ViewState("Rows")))
Else
Return 0
End If
End Get
Set(ByVal value As Integer)
ViewState("Rows") = value
End Set
End Property
' Columns property to hold the Columns in the ViewState
Protected Property Columns() As Integer
Get
If Not ViewState("Columns") Is Nothing Then
Return CInt(Fix(ViewState("Columns")))
Else
Return 0
End If
End Get
Set(ByVal value As Integer)
ViewState("Columns") = value
End Set
End Property
Sub listNow(ByVal sender As Object, ByVal e As EventArgs)
Dim titleSQL = "Select blogTitle,blogger from tblBlogs"
Dim con As New OleDbConnection("PROVIDER =Microsoft.ACE.OleDb.12.0; data source= " & server.MapPath("/mydatabase.accdb"))
Dim adap As New OleDbDataAdapter(titleSQL, con)
Dim ds1 As New Dataset()
Dim vTable As DataTable
Dim cmd =New OledbCommandBuilder(adap)
con.Open
adap.Fill(ds1,"pangLoad")
con.Close()
' Run only once a postback has occured
If Page.IsPostBack Then
'Set the Rows and Columns property with the value coming from the database
Me.Rows = ds1.tables("pangLoad").Rows.Count
Me.Columns = 1
End If
Me.Rows = ds1.tables("pangLoad").Rows.Count
Me.Columns = 1
CreateDynamicTable(titleSQL)
End Sub
Public Sub CreateDynamicTable(ByVal str as String)
PlaceHolder1.Controls.Clear()
'Load data from the database
Dim con As New OleDbConnection("PROVIDER =Microsoft.ACE.OleDb.12.0; data source= " & server.MapPath("/joan/AIMDbase.accdb"))
Dim adap As New OleDbDataAdapter(str, con)
Dim ds1 As New Dataset()
Dim cmd =New OledbCommandBuilder(adap)
con.Open
adap.Fill(ds1,"pangLoad")
con.Close()
' Fetch the number of Rows and Columns for the table
' using the properties
Dim tblRows As Integer = Rows
Dim tblCols As Integer = Columns
' Create a Table and set its properties
Dim tbl As Table = New Table()
' Add the table to the placeholder control
PlaceHolder1.Controls.Add(tbl)
' Now iterate through the table and add your controls
For i As Integer = 0 To tblRows - 1
Dim tr As TableRow = New TableRow()
For j As Integer = 0 To tblCols - 1
Dim tc As TableCell = New TableCell()
Dim lblQs As LinkButton = New LinkButton()
lblQs.Text = ds1.Tables("pangLoad").Rows(i).Item("blogTitle")
lblQs.OnClick="ListContent"
' Add the control to the TableCell
tc.Controls.Add(lblQs)
' Add the TableCell to the TableRow
tr.Cells.Add(tc)
Next j
tbl.Rows.Add(tr)
Next i
' This parameter helps determine in the LoadViewState event,
' whether to recreate the dynamic controls or not
ViewState("dynamictable") =true
End Sub
' Check the ViewState flag to determine whether to
' rebuild your table again
Protected Overrides Sub LoadViewState(ByVal earlierState As Object)
MyBase.LoadViewState(earlierState)
If ViewState("dynamictable") Is Nothing Then
CreateDynamicTable("")
End If
End Sub
</script>
....并在我的HTML身上
.... and on my html body
<table width="1037" border="0">
<tr>
<td width="263" bgcolor="#FF9900"><strong>BLOGS</strong></td>
<td width="764"> </td>
</tr>
<tr>
<td bgcolor="#FF9900"><asp:PlaceHolder ID="PlaceHolder1" runat="server" OnLoad="listNow" ></asp:PlaceHolder></td>
<td width="764"> </td>
</tr>
</table>
我想要的是每当页面加载时,所有应该加载我的数据库中的博客标题(我成功地完成了它)。一旦用户点击我创建的标题作为链接按钮,相应的内容必须出现在内容页面上。但不幸的是,我不能这样做。
请帮助。
谢谢!
What I want is whenever the page loads, all blog titles in my database should be loaded(and i successfully did it). Once the user click on title which i created as linkbutton, the corresponding content must appear on the content page. but unfortunately, i can't do it.
please help.
thanks!
推荐答案
这篇关于LinkButton的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文