zoukankan      html  css  js  c++  java
  • asp.net ListView控件的简单实用和配置

    1 web窗体界面代码

    ItemType:控件要绑定的实体模型
    SelectMethod:控件获取实体集合的后台方法
    DataKeyNames:实体的主键
    UpdateProduct:设置跟新的方法
    DeleteMethod:删除实体的方法
    InsertProduct:插入实体的方法
    InsertItemPosition:新插入实体的位置
    EnableViewState:禁用视图状态
    这些方法都可以在自定义在web窗体的代码后置中
     <asp:ListView runat="server" ItemType="SportsStore.Models.Product" SelectMethod="GetProducts"
            DataKeyNames="ProductID" UpdateMethod="UpdateProduct" DeleteMethod="DeleteProduct"
            InsertMethod="InsertProduct" InsertItemPosition="LastItem" EnableViewState="false">
    
            <LayoutTemplate>
                <div class="outerContainer">
                    <table id="productsTable">
                        <tr>
                            <th>Name</th>
                            <th>Description</th>
                            <th>Category</th>
                            <th>Price</th>
                        </tr>
                        <tr runat="server" id="itemPlaceholder">
                        </tr>
                    </table>
                </div>
            </LayoutTemplate>
    
            <ItemTemplate>
                <tr>
                    <td><%#Item.Name %></td>
                    <td class="description">
                        <span>
                            <%#Item.Description %>
                        </span>
                    </td>
                    <td><%#Item.Category %></td>
                    <td><%#Item.Price.ToString("c") %></td>
                    <td>
                        <asp:Button CommandName="Edit" Text="Edit" runat="server" />
                        <asp:Button CommandName="Delete" Text="Delete" runat="server" />
                    </td>
                </tr>
            </ItemTemplate>
    
            <EditItemTemplate>
                <tr>
                    <td>
                        <input name="name" value="<%#Item.Name%>" />
                        <input type="hidden" name="ProductID" value="<%#Item.ProductID%>" />
                    </td>
                    <td>
                        <input name="description" value="<%#Item.Description %>" />
                    </td>
                    <td>
                        <input name="category" value="<%#Item.Category %>" />
                    </td>
                    <td>
                        <input name="price" value="<%#Item.Price %>" />
                    </td>
                    <td>
                        <asp:Button CommandName="Update" Text="Update" runat="server" />
                        <asp:Button CommandName="Cancel" Text="Cancel" runat="server" />
                    </td>
                </tr>
            </EditItemTemplate>
    
            <InsertItemTemplate>
                <tr>
                    <td>
                        <input name="name"  />
                        <input type="hidden" name="ProductID" value="0" />
                    </td>
                    <td>
                        <input name="description" />
                    </td>
                     <td>
                        <input name="category" />
                    </td>
                     <td>
                        <input name="price"  />
                    </td>
                    <td>
                        <asp:Button CommandName="Insert"  Text="Add" runat="server"/>
                    </td>
                </tr>
            </InsertItemTemplate>
    
        </asp:ListView>

     这个控件包含了几个不同的模板,效果如下:

  • 相关阅读:
    C# 3.0新特性
    WinForm上显示gif动画
    Sql Server中Case函数的使用(上篇)转载
    Jquery的$命名冲突:
    Sql Server中case函数的使用(下篇) 转载
    hdu 2544 2066 1874 2680
    伤感!
    hdu 1999 不可摸数
    hdu 1878欧拉回路
    hdu 2767
  • 原文地址:https://www.cnblogs.com/mibing/p/7606331.html
Copyright © 2011-2022 走看看