下拉列表绑定

<textarea cols="50" rows="15" name="code" class="c-sharp:collapse"> #region 下拉列表绑定 /// &lt;summary&gt; /// 绑定指定下拉控件的数据源 /// &lt;/summary&gt; /// &lt;param name="ddl"&gt;下拉控件&lt;/param&gt; /// &lt;param name="dt"&gt;数据源&lt;/param&gt; /// &lt;param name="dataTextField"&gt;列表项文字字段&lt;/param&gt; /// &lt;param name="dataValueField"&gt;列表项值字段&lt;/param&gt; public static void BindDropDownList(System.Web.UI.WebControls.DropDownList ddl, DataTable dt, string dataTextField, string dataValueField, Enums.ddlIndexItemValueType dvt) { ddl.DataSource = dt; ddl.DataTextField = dataTextField; ddl.DataValueField = dataValueField; DataRow dr = dt.NewRow(); switch (dvt) { case Enums.ddlIndexItemValueType.空字符串: dr[dataValueField] = ""; break; case Enums.ddlIndexItemValueType.零: dr[dataValueField] = "0"; break; default: dr[dataValueField] = "0"; break; } dr[dataTextField] = "请选择..."; dt.Rows.InsertAt(dr, 0); ddl.DataBind(); } #endregion </textarea> 

你可能感兴趣的:(下拉列表绑定)