代码之家  ›  专栏  ›  技术社区  ›  MattSlay

ASP.NET新手需要的主/详细帮助。(还有截图)

  •  1
  • MattSlay  · 技术社区  · 17 年前

    http://www.twitpic.com/2gnmr

    我需要帮助了解在主列表中使用什么类型的HTML元素,以及在该元素上使用什么事件/触发器触发“获取此选定项的子记录”序列?

    此外,ListView是否是显示主列表的正确方法?目前,我不打算提供任何编辑功能;我想我以后再谈。

    我是否应该使用其他ASP.NET数据控件,而不是像现在这样手工编写listview?

    我不想在每个客户名称旁边看到一个实际的“选择”链接项目(看起来很愚蠢)。我希望客户名称是要单击的链接。

    <asp:ListView ID="ListView1" runat="server">
        <LayoutTemplate>
          <table cellpadding="2" border="0" ID="tbl1" runat="server">
            <tr id="Tr1" runat="server" class="lvHeader">
              <th id="Th1" runat="server">Customer</th>
            </tr>
            <tr runat="server" id="itemPlaceholder" />
          </table>
        </LayoutTemplate>
        <ItemTemplate>
          <tr id="Tr2" runat="server">
            <td>
              <asp:Label ID="label2" class="FirstLine" runat="server" Text='<%# Eval("company") %>' />
              <br />
              <div class="SecondLine">
                <asp:Label ID="labelCustNo" runat="server" Text='<%# Eval("custno") %>'/>
                <asp:Label runat="server" Text='Ph: '></asp:Label>
                <asp:Label ID="label3" runat="server" Text='<% # Eval("phone") %>' />
              </div>
            </td>
          </tr>
        </ItemTemplate>
    </asp:ListView>
    
    1 回复  |  直到 17 年前
        1
  •  2
  •   bendewey    17 年前

    我个人还没有发现ListView不能解决我的需求的情况。如果要创建客户选择样式列表,可以使用链接按钮进行绑定。

    <asp:ListView runat="server" id="CustomersList" ItemCommand="CustomersList_ItemCommand">
      <LayoutTemplate>
        <table cellpadding="2" border="0" ID="tbl1" runat="server">
          <tr id="Tr1" runat="server" class="lvHeader">
            <th id="Th1" runat="server">Customer</th>
          </tr>
          <tr runat="server" id="itemPlaceholder" />
        </table>
      </LayoutTemplate>
      <ItemTemplate>
        <tr id="Tr2" runat="server">
          <td>
            <asp:LinkButton ID="link1" class="FirstLine" runat="server" Text='<%# Eval("company") %>' CommandName="Select" />
            <br />
            <div class="SecondLine">
              <asp:Label ID="labelCustNo" runat="server" Text='<%# Eval("custno") %>'/>
              <asp:Label runat="server" Text='Ph: '></asp:Label>
              <asp:Label ID="label3" runat="server" Text='<% # Eval("phone") %>' />
            </div>
          </td>
        </tr>
      </ItemTemplate>
    </asp:ListView>
    
    <asp:ListView runat="server" ID="OrderList">
      <!-- Child Rows implementation -->
    </asp:ListView>
    

    然后需要将事件绑定到ListView.ItemCommand。

    protected void CustomersList_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
      if (e.CommandName = "Select")
      {
        if (e.Item.ItemType != ListViewItemType.DataItem) return;
    
        var dataItem = e.Item as ListViewDataItem;
        if (dataItem == null) return;
    
        var customer = dataItem.DataItem as Customer;
        if (customer == null) return;
    
        this.OrdersList.DataSource = GetChildRecords(customer.ID);
        this.OrdersList.DataBind();
      }
    }
    
    推荐文章