zoukankan      html  css  js  c++  java
  • 有一个无效 SelectedValue,因为它不在项目列表中

    有一个无效 SelectedValue,因为它不在项目列表中

    这个错误让我头疼了很长时间,在网上也查找了很多方法,但对我来说好像不奏效。

    找来找去,最后还是决定用笨方法来解决。


      protected void XX_DataBinding(object sender, EventArgs e)
        {

            DropDownList ddl = (DropDownList)sender;

            ddl.Items.Add("");

            CreateDDL("select dataValue from daiBasicData where dataClass='XX' ", ddl);

          
            DataRowView  dr = (DataRowView)DetailsView1.DataItem;
            int i = ddl.Items.IndexOf(ddl.Items.FindByValue(dr.Row["aField"].ToString()));
            if (i == -1) i = 0;
            ddl.SelectedValue = ddl.Items[i].Value;

        }

       private void CreateDDL(String sql, DropDownList ddl)
        {
            try
            {
                if (conn != null)
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        SqlCommand comd = new SqlCommand();
                        comd.Connection = conn;
                        comd.CommandText = sql;
                        SqlDataReader reader = comd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                if (reader[0] != System.DBNull.Value)
                                    ddl.Items.Add(reader[0].ToString());
                            }
                        }
                        reader.Close();
                        comd.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }

  • 相关阅读:
    The test form is only available for requests from the local machine
    64位Win7下,先安装Visual Studio,后安装IIS的设置步骤
    [转] 如何在 64 位的 Windows 7 中安裝 PLSQL DEVELOPER 8 和 Oracle 11g x64 Client
    excel对csv的转义
    js中没有引用的匿名函数调用方法
    缓存实现条件
    js对象成员的删除特性 (delete)
    js语法作用域之间的相关性
    【转】UBOOT之四:uboot.lds分析
    linux C 中的volatile使用
  • 原文地址:https://www.cnblogs.com/liuzhengdao/p/1282769.html
Copyright © 2011-2022 走看看