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>

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

  • 相关阅读:
    @RequestParam注解使用:Name for argument type [java.lang.String] not available, and parameter name information not found in class file either.
    cglib动态代理导致注解丢失问题及如何修改注解允许被继承
    springboot Autowired BeanNotOfRequiredTypeException
    git根据用户过滤提交记录
    不同包下,相同数据结构的两个类进行转换
    How to use Jackson to deserialise an array of objects
    jooq实践
    java如何寻找main函数对应的类
    Python--matplotlib
    Python 和 Scikit-Learn
  • 原文地址:https://www.cnblogs.com/mibing/p/7606331.html
Copyright © 2011-2022 走看看