zoukankan      html  css  js  c++  java
  • 使用repeater tableb绑定数据库

    1:前台代码:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Repeater.aspx.cs" Inherits="Repeater" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate>
            <table>
            <tr>
        <td align="center">学号</td>
        <td align="center">姓名</td>
        <td align="center">性别</td>
        <td align="center">专业名称</td>
        <td align="center">地址</td>
        </tr>
        </HeaderTemplate>
        <ItemTemplate>
        <tr>
        <td align="center"><asp:TextBox ID="txtNo" runat="server" Text='<%#Eval("StuId")%>' ReadOnly="true"></asp:TextBox></td>
         <td align="center"><asp:TextBox ID="txtName" runat="server" Text='<%#Eval("StuName")%>' ReadOnly="true"></asp:TextBox></td>
          <td align="center"><asp:TextBox ID="txtSex" runat="server" Text='<%#Eval("StuSex")%>' ReadOnly="true"></asp:TextBox></td>
           <td align="center"><asp:TextBox ID="txtSP" runat="server" Text='<%#Eval("Speciality")%>' ReadOnly="true"></asp:TextBox></td>
            <td align="center"><asp:TextBox ID="txtAddress" runat="server" Text='<%#Eval("StuAddress")%>' ReadOnly="true"></asp:TextBox></td>
        </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
        <tr>
        <td align="center"><asp:TextBox ID="txtNo" runat="server" Text='<%#Eval("StuId")%>' ReadOnly="true"></asp:TextBox></td>
         <td align="center"><asp:TextBox ID="txtName" runat="server" Text='<%#Eval("StuName")%>' ReadOnly="true"></asp:TextBox></td>
          <td align="center"><asp:TextBox ID="txtSex" runat="server" Text='<%#Eval("StuSex")%>' ReadOnly="true"></asp:TextBox></td>
           <td align="center"><asp:TextBox ID="txtSP" runat="server" Text='<%#Eval("Speciality")%>' ReadOnly="true"></asp:TextBox></td>
            <td align="center"><asp:TextBox ID="txtAddress" runat="server" Text='<%#Eval("StuAddress")%>' ReadOnly="true"></asp:TextBox></td>
        </tr>
        </AlternatingItemTemplate>
          <FooterTemplate>
         </table>
       </FooterTemplate>
            </asp:Repeater>
        </div>
        </form>
    </body>
    </html>
    View Code

    2:后台代码:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.OracleClient;
    using System.Configuration;
    using System.Text;
    
    public partial class Repeater : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
    
        private void BindData()
        {
            StringBuilder strb = new StringBuilder();
            strb.Append("select t.*");
            strb.Append("from Student t");
            string strConn = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
            using (OracleConnection con = new OracleConnection(strConn))
            {
                con.Open();
                using (OracleCommand cmd = new OracleCommand(strb.ToString(), con))
                {
                    using (OracleDataAdapter da = new OracleDataAdapter(cmd))
                    {
                        DataSet ds = new DataSet();
                        da.Fill(ds, "Student");
                       Repeater1.DataSource=ds.Tables["Student"];
                       Repeater1.DataBind();
                    }
    
                }
    
            }
        }
        
    }
    View Code

    3:效果截图:

  • 相关阅读:
    bzoj-2748 2748: [HAOI2012]音量调节(dp)
    bzoj-2338 2338: [HNOI2011]数矩形(计算几何)
    bzoj-3444 3444: 最后的晚餐(组合数学)
    codeforces 709E E. Centroids(树形dp)
    codeforces 709D D. Recover the String(构造)
    codeforces 709C C. Letters Cyclic Shift(贪心)
    codeforces 709B B. Checkpoints(水题)
    codeforces 709A A. Juicer(水题)
    Repeat Number
    hdu 1003 Max Sum (动态规划)
  • 原文地址:https://www.cnblogs.com/thbbsky/p/3093272.html
Copyright © 2011-2022 走看看