从数组源填充gridview中的下拉列表

时间:2013-08-29 13:08:19

标签: c# asp.net arrays gridview

我一直在尝试从数组源填充我的gridview中的dropdownlist,但它似乎只读取了第一个数组元素。我尝试用面板做它并且它有效。这是我的代码。

       public partial class Default2 : System.Web.UI.Page
       {
       DataTable dtnew = new DataTable();

        protected void Page_Load(object sender, EventArgs e)
        {
        string[] excel = new string[10];
        DataTable dtt = (DataTable)Session["griddata"];
        for (int i = 0; i < dtt.Columns.Count; i++)
        {
            excel[i] = dtt.Columns[i].ColumnName; //column names from a datatable stored in the array
        }

        Session["exceldata"] = excel;


        string[] sqlcolumn = new string[10];
        DataTable dtt1 = (DataTable)Session["dbasecolumns"];
        for (int j = 0; j < dtt1.Columns.Count; j++)
        {
            sqlcolumn[j] = dtt1.Columns[j].ColumnName; //column names from a datatable stored in the array
        }
        Session["excel"] = sqlcolumn;

        DropDownList drd = new DropDownList();
        dtnew.Columns.Add(new DataColumn("database", typeof(string)));
        dtnew.Columns.Add(new DataColumn("excel", typeof(string)));
       // DataRow dr = new DataRow();
        foreach (String colname in sqlcolumn)
        {


            drd.Items.Add(colname);
          //  drd.Items.Add(new ListItem(colname));


        }

        for (int i = 0; i < sqlcolumn.Length; i++)
        {
            DataRow dr = dtnew.NewRow();
            dtnew.Rows.Add(dr);
            {


                dr["excel"] = string.Empty;
                dr["database"] = drd;
            }

        }
        //Panel1.Controls.Add(drd);


       GridView1.DataSource = dtnew;
       GridView1.DataBind();

    }
    }

似乎只用数组的第一个元素填充我的GridView列,这也是一个简单的文本(而不是下拉列表)。我怎么能实现这个目标。

提前致谢

0 个答案:

没有答案