⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linkbuttonlist.aspx

📁 asp.net技术内幕的书配源码
💻 ASPX
字号:
<%@ Import Namespace="System.Data.SqlClient" %>

<Script Runat="Server">

Sub Page_Load
  If Not IsPostBack Then
    Dim conNorthwind As SqlConnection
    Dim cmdSelect As SqlCommand
    Dim dtrCategories As SqlDataReader

    conNorthwind = New SqlConnection( "Server=localhost;UID=sa;PWD=secret;Database=Northwind" )
    cmdSelect = New SqlCommand( "Select CategoryName From Categories", conNorthwind )
    conNorthwind.Open()
    dtrCategories = cmdSelect.ExecuteReader()

    rptCategories.DataSource = dtrCategories
    rptCategories.DataBind()

    dtrCategories.Close()
    conNorthwind.Close()
  End If
End Sub

Sub Button_Click( s As Object, e As RepeaterCommandEventArgs )
  Dim lbtnSelected As LinkButton

  lbtnSelected = e.Item.Controls( 1 )
  lblCategory.Text = "You selected " & lbtnSelected.Text
End Sub

</Script>

<html>
<head><title>LinkButtonList.aspx</title></head>
<body>
<form Runat="Server">

<asp:Repeater
  ID="rptCategories"
  OnItemCommand="Button_Click"
  Runat="Server">

<ItemTemplate>
  <li>
  <asp:LinkButton
   Text='<%# Container.DataItem( "CategoryName" ) %>'
   Runat="Server" />
</ItemTemplate>

</asp:Repeater>

<p>
<asp:Label
  ID="lblCategory"
  Runat="Server" />

</form>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -