WebForm数据绑定

2021-06-10 13:02

阅读:328

YPE html>

标签:connect   ring   using   char   run   exec   oev   nic   --   

Users表

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// 
/// Users 的摘要说明
/// 
public class Users
{
    public Users()
    {

    }
    public int Ids { get; set; }
    public string Ucode { get; set; }
    public string UserName { get; set; }
    public string password { get; set; }
    public string NickName { get; set; }
    public bool Sex { get; set; }
    public string Sexstr
    {
        get
        {
            return Sex ? "" : "";
        }
    }
    public DateTime Birthday { get; set; }
    public string Nation { get; set; }
    public string NationName
    {
        get
        {
            string s = "";
            SqlConnection conn = new SqlConnection("server=.;database=Date0504;user=sa;pwd=y920106k");
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "select * from UserNation where NationCode=@a";
            cmd.Parameters.Add("@a",Nation);
            conn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                s = dr["NationName"].ToString();
            }
            conn.Close();
            return s;
        }

    }

 

UsersData

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

/// 
/// UsersData 的摘要说明
/// 
public class UsersData
{
    SqlConnection conn;
    SqlCommand cmd;
    public UsersData()
    {
        conn = new SqlConnection("server=.;database=Date0504;user=sa;pwd=y920106k");
        cmd = conn.CreateCommand();
    }
    public ListSelectAll()
    {
        List ulist = new List();
        cmd.CommandText = "select * from Users";
        conn.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            Users u = new Users();
            u.Ids = Convert.ToInt32(dr["Ids"]);
            u.Ucode = dr["Ucode"].ToString();
            u.UserName = dr["UserName"].ToString();
            u.password = dr["PassWord"].ToString();
            u.NickName = dr["NickName"].ToString();
            u.Sex = Convert.ToBoolean(dr["Sex"]);
            u.Birthday = Convert.ToDateTime(dr["Birthday"]);
            u.Nation = dr["Nation"].ToString();
            ulist.Add(u);
        }
        conn.Close();
        return ulist;
    }
}

 

Default

"C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>



"http://www.w3.org/1999/xhtml">"server">
    "Content-Type" content="text/html; charset=utf-8" />
    
"form1" runat="server">
"Repeater1" runat="server">
Ids 编号 用户民 密码 昵称 性别 生日 民族
"Ids") %> "Ucode") %> "UserName") %> "Password") %> "NickName") %> "Sexstr") %> "Birthday","{0:yyyy年MM月dd日}") %> "NationName") %>

 

Default右键查看代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Repeater1.DataSource = new UsersData().SelectAll();//指定数据源
        Repeater1.DataBind();//绑定数据源
    }
}

 

WebForm数据绑定

标签:connect   ring   using   char   run   exec   oev   nic   --   

原文地址:http://www.cnblogs.com/skyhorseyk/p/7296013.html

上一篇:html5 游戏开发

下一篇:HTML基础


评论


亲,登录后才可以留言!