zoukankan      html  css  js  c++  java
  • ASP.NET控件绑定数据源

    1. DataList/GridView/Repeater

      DataSet表示数据集,其中包含表,约束和表之间的关系。与现有数据源的交互通过DataAdapter来控制。

      源代码示例:

      SqlDataAdapter da=new SqlDataAdapter(strsql,con);

      DataSet ds=new DataSet();

      da.Fill(ds);

    GridView1.DataSource = ds.Tables[0];

    GridView1.DataBind();

    1. ListBox

      源码示例:

      ListBox1.DataSource=ds.Tables[0];

      ListBox1.DataTextField="MenuName";

      ListBox1.DataValueField="MId";

      ListBox1.DataBind();

    2. DropDownList

      源码示例1:

      DropDownList1.DataSource=ds.Tables[0];

      DropDownList1.DataTextField=ds.Tables[0].Columns[0].ToString();

      DropDownList1.DataBind();

      //DropDownList1.Item.Insert(0,"请选择");

      源码示例2:(绑定数组数据)

          ArrayList ListItem=new ArrayList();

          ListItem.Add("###");

          ListItem.Add("###");

          ListItem.Add("###");

          ListItem.Add("###");

          DropDownList1.DataSource=ListItem;

          DropDownList1.DataBind();

    3. TreeView数据绑定

      [1].TreeView控件可以实现IhierachicalDataSource接口的任意数据源控件,例如XmlDataSource或SiteMapDataSource控件,若要绑定到数据源控件,将TreeView控件的DataSourceID属性设置为对应数据源控件ID值

      [2].TreeView控件还可以绑定到XmlDocument对象或DataSet对象,若要绑定到这些数据源,将TreeView控件多的DataSource属性设置为该数据源,然后调用DataBind()方法

    4. Xml数据绑定到GridView

      Xml数据,

      DataSet对象的内容可以从Xml流或文档中创建,使用Xml中的数据填充DataSet对象,主要使用该对象的ReadXml()方法,DataSet.ReadXml();

      源码示例:

        DataSet ds = new DataSet();

        ds.ReadXml(Server.MapPath("News.xml"));

        GridView1.DataSource = ds.Tables[0].DefaultView;

      GridView1.DataBind();

    1. Menu

      [1].将Menukong控件的DataSourceID绑定到相应数据源控件的ID值,实现与相应数据源的关联。

      [2].绑定XmlDocument或者DataSet对象等,处理这类数据绑定时关键是设置DataSource属性和调用DataBind()方法。

  • 相关阅读:
    对cross-env的理解
    【好好学习】mh_h5
    QS工具入门
    vue中用qs传参发送axios请求
    Web API 异常处理
    WEB API Filter的使用以及执行顺序
    RSA/SHA1加密和数字签名算法在开放平台中的应用
    windows上RSA密钥生成和使用
    Cordova Error: cmd: Command failed with exit code ENOENT
    Cordova热更新cordova-hot-code-push
  • 原文地址:https://www.cnblogs.com/weihanli/p/3412692.html
Copyright © 2011-2022 走看看