2014-04-07 44 views
0

我從代碼創建一個動態下拉列表後面:添加一個動態的DropDownList到GridView(然後導出到Excel)

protected void test_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    DropDownList ddlSelection = new DropDownList(); 


    string value = ""; 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     DataRow row = ((DataRowView)e.Row.DataItem).Row; 
     value = row.Field<String>("[First Row]"); 
    } 
    List<string> mylist = new List<string>(); 
    mylist.Add("NORMAL"); 
    mylist.Add("LOW"); 

    ddlSelection.DataSource = mylist; 
    ddlSelection.DataBind(); 
    ddlSelection.SelectedValue = value; 
    e.Row.Cells[0].Controls.Add(ddlSelection); 
} 

然後我將其導出到Excel。一切都很好,希望DropDownList需要放在單元格內(cf:下面的圖片)。

enter image description here

的DropDownList的推移其細胞外。我怎麼能修好它?

+0

您是如何將dropdownlist控件導出爲ex​​cel的? –

回答

0

這是一個部分解決方案

e.Row.Cells[0].Width = Unit.Pixel(200); 

但我想使其動態。是否有可能知道DropDownList的寬度?

我試過這個,但它不起作用。 ddlSelection.Width值= 0.

e.Row.Cells[0].Width = ddlSelection.Width; 
相關問題