0

我一直在尝试从数组源填充我的 gridview 中的下拉列表,但它似乎只读取了第一个数组元素。我试着用一个面板来做这件事,它起作用了。这是我的代码。

       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 列,而且它也是一个简单的文本(而不是下拉列表)。我怎么可能实现这一点。

提前致谢

4

0 回答 0