Hopes

          Start Here..

           

          ASP.Net中的關于數據綁定

          ASP.Net中的關于數據綁定

          1. 綁定標簽 <%# …… %> 可綁定標簽屬性值,表達式,方法的結果及數據源等。

          a. 綁定屬性之label的Text屬性值 :

          <asp: label1 ID="labtxt" Text="<%# DataTime.Now.ToShortString() %>" >

          this.label1.DataBind();***************后臺代碼千萬不能少

          b.綁定變量

          后臺代碼類中定義一變量 protected Color bgcolor=Color.FromA#b48cd2;

          前臺 <asp: label1 ID="labtxt" BackColor="<%# bgcolor %>" runat="server">

          this.labtxt.DataBind();

          c.綁定常量

          后臺 protected int a=15;

          protected int b=10;

          <td> a+b=<%# a+b %> <td>

          this.DataBind();

          d.綁定 方法

          在后面寫個方法 protected string GetDate(){……}

          在前臺 <td> 今天:<%# GetData() %> </td>

          this.DataBind();

          e.綁定 數組集合

          Protected string[] strarray={"acb","def","xyz"};

          < asp: DropDownList DataSource="<%# strarray %>" >

          this.DataBind();

          ASP.Net綁定數據源

          1.使用DropDownList手動綁定數據源

          public void GetBinds()

          {

          DataTable tb= GetTable(……);

          this.DropDownList.DataSource=tb;

          this.DropDownList.DataTextField="類別"; //可見值

          this.DropDownList.DataValueField="ID" //隱藏值

          }

          調用該 方法后記的 加上 this.DataBind();



          2. 篇歷的 ChickBoxList

          for (int i=0; i<checkboxlist1.Items.Count; i++)
          {
          if (checkboxlist1.Items[i].Selected)
          {
          Label1.Text += checkboxlist1.Items[i].Text + "<br />";
          }
          }

          posted on 2012-09-16 14:02 ** 閱讀(135) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          統計

          公告

          你好!

          常用鏈接

          留言簿(2)

          隨筆檔案

          文章分類

          文章檔案

          新聞檔案

          相冊

          收藏夾

          C#學習

          友情鏈接

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 甘南县| 拉孜县| 双江| 铅山县| 建昌县| 娄底市| 江口县| 阆中市| 疏勒县| 五寨县| 克拉玛依市| 吉隆县| 隆安县| 平阳县| 车险| 长寿区| 河池市| 通辽市| 青海省| 望城县| 龙江县| 芦山县| 三河市| 南漳县| 巍山| 绥化市| 青神县| 东丽区| 登封市| 灵台县| 榆树市| 津市市| 荥经县| 榆林市| 金昌市| 筠连县| 万州区| 南丰县| 郎溪县| 青岛市| 土默特右旗|