初始化下拉列表

 #region 初始化下拉列表
    public static void InitDDL(string sSQL, DropDownList ddl, string sFieldID, string sFieldName, string sSelectFieldNameValue, bool bAll)
    {
        string sError = "";
        DataTable dt = RB.SqlHelper.RunQuery(CommandType.Text, sSQL, null, out sError);
        if (sError.Equals(""))
        {
            ddl.Items.Clear();
            ddl.DataSource = dt;
            ddl.DataTextField = sFieldName;
            ddl.DataValueField = sFieldID;
            ddl.DataBind();
            if (bAll) ddl.Items.Insert(0, new ListItem("---请选择---", ""));
            if (!sSelectFieldNameValue.Equals("")) ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByText(sSelectFieldNameValue));
        }
    }
    public static void InitDDL(object list, DropDownList ddl, string sFieldID, string sFieldName, string sSelectFieldNameValue)
    {
        ddl.Items.Clear();
        ddl.DataSource = list;
        ddl.DataTextField = sFieldName;
        ddl.DataValueField = sFieldID;
        ddl.DataBind();
        ddl.Items.Insert(0, new ListItem("请选择", ""));
        ddl.SelectedValue = sSelectFieldNameValue;

    }
    #endregion

posted @ 2012-11-28 17:23  天天代码码天天  阅读(6)  评论(0编辑  收藏  举报  来源