2014-04-07 42 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; 
相关问题