ASP.NET伺服器控制項資料繫結總結

來源:互聯網
上載者:User

標籤:

  1 using System;  2 using System.Collections.Generic;  3 using System.Text;  4 using System.Web.UI.WebControls;//  5 using System.Data.SqlClient;  6 using System.Data;//  7 using System.Web.UI;//  8 using Wuqi.Webdiyer;//此控制項請在網上下載  9  10 namespace Study 11 { 12     public sealed class WebControlsBind 13     { 14        #region DropDownlist 綁定 49         /// <summary> 50         /// 綁定DropDownList控制項 51         /// </summary> 52         /// <param name="p_ddlControl">控制項</param> 53         /// <param name="p_drSource">資料來源</param> 54         /// <param name="p_strText">文本值</param> 55         /// <param name="p_strValue">值</param> 56         /// <param name="p_blAll">是否包含全部項,若不包含返回false,若包含返回true</param> 57         public static void BindDDL(DataTable p_drSource, DropDownList p_ddlControl, string p_strText, string p_strValue, bool p_blAll) 58         { 59             p_ddlControl.DataSource = p_drSource; 60             p_ddlControl.DataTextField = p_strText; 61             p_ddlControl.DataValueField = p_strValue; 62             p_ddlControl.DataBind(); 63             if (p_blAll == true) 64             { 65                 ListItem li = new ListItem("全部", "0"); 66                 p_ddlControl.Items.Insert(0, li);//使用add方法只能添加到最後,使用Insert方法可以添加到指定的位置 67  68             } 69         } 70  71         #endregion 72  73         #region 帶分頁的資料繫結Repeater控制項 74         /// <summary> 75         /// 帶分頁的Repeater的資料繫結 76         /// </summary> 77         /// <param name="dsSource">資料來源</param> 78         /// <param name="rpt">Repeater控制項</param> 79         /// <param name="anp">分頁控制項</param> 80         public static void Bindrpt(DataTable dsSource, Repeater rpt, AspNetPager anp) 81         { 82             DataView dv = dsSource.DefaultView; 83             anp.RecordCount = dv.Count; 84             if (dv.Count > 0) 85             { 86                 PagedDataSource pds = new PagedDataSource(); 87                 pds.DataSource = dv; 88                 pds.AllowPaging = true; 89                 pds.CurrentPageIndex = anp.CurrentPageIndex - 1; 90                 pds.PageSize = anp.PageSize; 91                 rpt.DataSource = pds; 92                 rpt.DataBind(); 93  94             } 95  96  97         } 98         public static void Bindrpt(DataTable dsSource, Repeater rpt, AspNetPager anp,string order) 99         {100             DataView dv = dsSource.DefaultView;101             dv.Sort = order;102             DataTable dt = dv.ToTable();103             anp.RecordCount = dv.Count;104             if (dv.Count > 0)105             {106                 PagedDataSource pds = new PagedDataSource();107                 pds.DataSource = dv;108                 pds.AllowPaging = true;109                 pds.CurrentPageIndex = anp.CurrentPageIndex - 1;110                 pds.PageSize = anp.PageSize;111                 rpt.DataSource = pds;112                 rpt.DataBind();113 114             }115 116 117         }118 119         #endregion120         #region 帶分頁的資料繫結Datalist控制項121         /// <summary>122         /// 帶分頁的Repeater的資料繫結123         /// </summary>124         /// <param name="dsSource">資料來源</param>125         /// <param name="dlt">DataList控制項</param>126         /// <param name="anp">分頁控制項</param>127         public static void BindDlt(DataTable dsSource, DataList dlt, AspNetPager anp)128         {129             DataView dv = dsSource.DefaultView;130             anp.RecordCount = dv.Count;131             if (dv.Count > 0)132             {133                 PagedDataSource pds = new PagedDataSource();134                 pds.DataSource = dv;135                 pds.AllowPaging = true;136                 pds.CurrentPageIndex = anp.CurrentPageIndex - 1;137                 pds.PageSize = anp.PageSize;138                 dlt.DataSource = pds;139                 dlt.DataBind();140 141             }142 143 144         }145 146 147         #endregion 148 149 150 151 152 153     }154 }

 

ASP.NET伺服器控制項資料繫結總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.