数据绑定_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > 数据绑定

数据绑定

 2014/4/21 15:30:28  小小潇洒哥儿  博客园  我要评论(0)
  • 摘要:WEB.config:<connectionStrings><addname="conn"connectionString="DataSource=orcl;UserID=qxw;Password=123456"providerName="System.Data.OracleClient"/></connectionStrings>数据库类:DBTool.cs:publicclassDBTool
  • 标签:数据

WEB.config:
  <connectionStrings>
    <add name="conn" connectionString="Data Source=orcl;User ID=qxw;Password=123456" providerName="System.Data.OracleClient"/>
  </connectionStrings>
数据库类:DBTool.cs:
    public class DBTool
    {

        public OracleConnection GetConnection()
        {
            string str = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
            OracleConnection conn = new OracleConnection(str);
            return conn;
        }


        public DataTable Get_FFLOWList()
        {
            string sql = "select * from rr";
            OracleConnection conn = GetConnection();
            OracleDataAdapter oda = new OracleDataAdapter(sql, conn);
            DataTable dt = new DataTable();
            oda.Fill(dt);
            return dt;
        }

    }
载入页面:
        protected void Page_Load(object sender, EventArgs e)
        {
            DBTool tool = new DBTool();
            DataTable dt = tool.Get_FFLOWList();

            GridView1.DataSource = dt;
            GridView1.DataBind();



            DataList1.DataSource = dt;
            DataList1.DataBind();

            Repeater1.DataSource = dt;
            Repeater1.DataBind();
        }
ASPX:
GridView:
        <asp:GridView ID="GridView1" runat="server" BackColor="LightGoldenrodYellow" 
            BorderColor="Tan" BorderWidth="1px" CellPadding="2" 
            EnableModelValidation="True" ForeColor="Black" GridLines="None">
            <AlternatingRowStyle BackColor="PaleGoldenrod" />
            <FooterStyle BackColor="Tan" />
            <HeaderStyle BackColor="Tan" Font-Bold="True" />
            <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" 
                HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
        </asp:GridView>
DataList:
        <asp:DataList ID="DataList1" runat="server" CellPadding="4" ForeColor="#333333">
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <HeaderTemplate>
        <table border="1">
        <tr><td>序号</td><td>名字</td></tr>
        </HeaderTemplate>
            <ItemStyle BackColor="#FFFBD6" ForeColor="#333333" />
        <ItemTemplate>
        <tr><td><%# DataBinder.Eval(Container.DataItem, "ID")%></td><td><%# DataBinder.Eval(Container.DataItem, "NAME")%></td></tr>
        </ItemTemplate>

            <AlternatingItemStyle BackColor="White" />
            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />

        <FooterTemplate>
        </table>
        </FooterTemplate>

            <SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />

        </asp:DataList>

Repeater:
        <asp:Repeater ID="Repeater1" runat="server" 
            onitemcommand="Repeater1_ItemCommand">
        <HeaderTemplate>
        <table border="1"><tr><td>IDD</td><td>NameE</td></tr>
        </HeaderTemplate>
        <ItemTemplate><tr><td><%# DataBinder.Eval(Container.DataItem, "ID")%></td><td><%# DataBinder.Eval(Container.DataItem, "NAME")%></td></tr></ItemTemplate>
        <AlternatingItemTemplate><tr style="background-color:gray;"><td><%# DataBinder.Eval(Container.DataItem, "ID")%></td><td><%# DataBinder.Eval(Container.DataItem, "NAME")%></td></tr></AlternatingItemTemplate>
        <FooterTemplate></table></FooterTemplate>
        </asp:Repeater>
发表评论
用户名: 匿名