• LINQ绑定List到GridView


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace _126
    {
        public partial class _126 : System.Web.UI.Page
        {
            Data126DataContext data = new Data126DataContext();
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    var users = from p in data._126
                                select new
                                {
                                    p.id,
                                    p.num,
                                    p.time
                                };
    
                    gve.DataSource = users.ToList();
                    gve.DataBind();
                }
                
            }
    
          
            protected void Button1_Click(object sender, EventArgs e)
            {
                _126 num = new _126();
                num.num = txtNum.Text;
                num.time = DateTime.Now;
    
                data._126.InsertOnSubmit(num);
                data.SubmitChanges();
    
                
            }
        }
    }
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="126.aspx.cs" Inherits="_126._126" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            数据:<asp:TextBox ID="txtNum" runat="server"></asp:TextBox>
    &nbsp;<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="添加" />
            <br />
            <asp:GridView ID="gve" runat="server" AutoGenerateColumns="False">
                <Columns>
                  <asp:BoundField DataField="id" HeaderText="用户名"/>
                  <asp:BoundField DataField="num" HeaderText="密码"/>
                  <asp:BoundField DataField="time" HeaderText="用户信息"/>
                  </Columns>
            </asp:GridView>
        
        </div>
        </form>
    </body>
    </html>
  • 相关阅读:
    PHP获取汉字拼音首字母
    记录,待总结5
    HDU2833 WuKong Floyd
    搜索
    记录,待总结4
    HDU3350 #define is unsafe 栈的应用
    指针与引用的混合使用总结
    多源最短路径 Floyd
    引用总结
    函数返回值总结
  • 原文地址:https://www.cnblogs.com/yangwujun/p/3405956.html
Copyright © 2020-2023  润新知