在学asp.net技术内幕这本书,有个例子中的一条语句不是很明白,请大家帮忙看看.代码:
<%@ Page Language="VB" Debug="true" %>
<%@ 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=;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 SubSub 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><ItemTemplate>
  <li>
  <asp:LinkButton
   Text='<%# Container.DataItem( "CategoryName" ) %>'
   Runat="Server" />
</ItemTemplate>
</asp:Repeater><p>
<asp:Label
  ID="lblCategory"
  Runat="Server" /></form>
</body>
</html>
========================其中的  lbtnSelected = e.Item.Controls( 1 )  ,为什么要用 1 呢?请大家帮忙解释一下,谢谢.

解决方案 »

  1.   

    这表明item这个结构(我自己的理解)controls结构(控件结构)包含两个控件(一个是专门显示的label标签(通常隐藏,看不出来),还有一个就是按钮)
      

  2.   

    上边的代码
    <ItemTemplate>
      <li>
      <asp:LinkButton
       Text='<%# Container.DataItem( "CategoryName" ) %>'
       Runat="Server" />
    </ItemTemplate><ItemTemplate>
      <li>
      <asp:LinkButton
       Text='<%# Container.DataItem( "CategoryName" ) %>'
       Runat="Server" />
    </ItemTemplate>源代码只有一个LinkButton,现在我另加上了相同一个LinkButton.前边没注意看.