我从后面的代码创建一个动态的DropDownlist:
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需要放在单元格内(参见下图)。
DropDownList超出其单元格。我该怎么办呢?
答案 0 :(得分:0)
这是部分解决方案
e.Row.Cells[0].Width = Unit.Pixel(200);
但我想动态地制作它。是否可以知道DropDownList的宽度?
我尝试了这个,但它不起作用。 ddlSelection.Width
值= 0。
e.Row.Cells[0].Width = ddlSelection.Width;