zoukankan      html  css  js  c++  java
  • Datalist 控件

    结构跟Repeater很相似 多出一组EditItemTemplate项

    在一下例子中使用CommandName属性指向某一个事件

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <asp:DataList ID="DataList1" runat="server" OnSelectedIndexChanged="DataList1_SelectedIndexChanged" OnEditCommand="DataList1_EditCommand" OnDeleteCommand="DataList1_DeleteCommand">
                <HeaderTemplate>
                    <table style="900px;background-color:#ffffcc"><tr>
                        <td width="25%">姓名</td>
                        <td>性别</td>
                        <td>电话</td>
                        <td>操作</td>
                    </tr></table>
                </HeaderTemplate>
    
                <ItemTemplate>
                    <table style="900px;background-color:#ffffcc"><tr>
                        <td width="25%">
                            <asp:Label ID="Label1" runat="server" Text='<%#Eval("code") %>'></asp:Label></td>
                        <td width="25%"><%#Eval("name") %></td>
                        <td width="25%"><%#Eval("tel") %></td>
                        <td width="25%">
                            <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit">编辑</asp:LinkButton>
                            <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Delete">删除</asp:LinkButton>
                            
                        </td>
                    </tr></table>
                </ItemTemplate>
    
                <EditItemTemplate>
                    <table style="900px;background-color:#ffffcc"><tr>
                        <td width="25%">
                            <asp:TextBox ID="txtname" runat="server" Text='<%#Eval("name") %>'></asp:TextBox></td>
                        <td width="25%">
                            <asp:TextBox ID="txtsex" runat="server" Text='<%#Eval("sex") %>'></asp:TextBox></td>
                        <td width="25%">
                            <asp:TextBox ID="txttel" runat="server" Text='<%#Eval("tel") %>'></asp:TextBox></td>
                        <td width="25%"><asp:LinkButton ID="LinkButton1" runat="server">更新</asp:LinkButton>
                            <asp:LinkButton ID="LinkButton2" runat="server">取消</asp:LinkButton></td>
                    </tr></table>
                </EditItemTemplate>
                <FooterTemplate></FooterTemplate>
            </asp:DataList>
        
        </div>
        </form>
    </body>
    </html>
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataList1.DataSource = new TelBF().Select();
                DataList1.DataBind();
            }
        }
    
    
        protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
        {
    
        }
        protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
        {
            //选中改行的索引
            DataList1.EditItemIndex = e.Item.ItemIndex;//EditItemTemplate项默认索引为-1时隐藏该项
            //重新绑定数据
            DataList1.DataSource = new TelBF().Select();
            DataList1.DataBind();
        }
        protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
        {
            Label la = (Label)e.Item.FindControl("Label1");
            string s = la.Text;
            new TelBF().Delete(s);
            DataList1.DataSource = new TelBF().Select();
            DataList1.DataBind();
        }
    }
  • 相关阅读:
    Windows7下安装golang语言开发环境和revel框架
    Go实战--通过gin-gonic框架搭建restful api服务(github.com/gin-gonic/gin)
    Go语言web框架 gin
    最好的6个Go语言Web框架
    mac:Go安装和配置+GoLand安装和使用之完整教程
    Goland软件使用教程(二)
    Goland软件使用教程(一)
    http_load常见问题及解决方案
    定义类和接口
    关于 xftp 上传文件时,仅仅是上传了0字节的问题
  • 原文地址:https://www.cnblogs.com/w-wz/p/4701123.html
Copyright © 2011-2022 走看看