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

📄 linkbuttonlist.aspx

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

<script runat=server>

void Page_Load(Object sender , EventArgs e) 
{
	if (! IsPostBack ) {
		SqlConnection conNorthwind;
		SqlCommand cmdSelect;
		SqlDataReader dtrCategories;

		conNorthwind = new SqlConnection( @"Server=localhost;Integrated Security=SSPI; Database=Northwind" );
		cmdSelect = new SqlCommand( "Select CategoryName From Categories", conNorthwind );
		conNorthwind.Open();
		dtrCategories = cmdSelect.ExecuteReader();

		rptCategories.DataSource = dtrCategories;
		rptCategories.DataBind();

		dtrCategories.Close();
		conNorthwind.Close();
	}
}

void Button_Click( object s, RepeaterCommandEventArgs e )
{
	LinkButton lbtnSelected = ((LinkButton)e.CommandSource);
	lblCategory.Text = "You selected " + lbtnSelected.Text;
}
</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='<%#DataBinder.Eval(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 + -