我有一个网格视图,其中有一列用于显示下拉列表。我已经将其设置为与我在网上看到的许多示例完全一样,但没有出现下拉列表。
这是我的gridview的asp:
<asp:GridView id="gvDetails" OnPreRender="DrawDetails" AutoGenerateColumns="false" OnRowDataBound="gvDetails_RowDataBound" width="100%" runat="server">
<columns>
<asp:BoundField
HeaderText="Description"
ShowHeader="true"
DataField="Description">
<itemStyle width="20%"/>
</asp:BoundField>
...
<asp:TemplateField
HeaderText="Status"
ShowHeader="true"
>
<ItemStyle width="16%"/>
<ItemTemplate >
<asp:DropDownList
id="ddlStatus"
Style="width:100%"
runat="server"
>
<asp:ListItem value="1">Closed</asp:ListItem>
<asp:ListItem value="2">Open</asp:ListItem>
<asp:ListItem value="3">Approved</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</columns>
我不确定您是否需要查看与 gridview 相关的代码(OnPreRender 和 RowDataBound)?让我知道,如果你这样做,我会编辑这个。不过,它并没有做任何不寻常的事情。
为什么这个下拉列表没有出现?
编辑:我在 gridview 的 RowDataBound 事件中添加了一些代码,如果它可以找到控件,它将输出到我的日志。它可以很好地找到控件,只是没有出现下拉列表。
编辑 2:根据要求,这里是 RowDataBound 事件:
protected void gvDetail_RowDataBound(Object sender, GridViewRowEventArgs e)
{
GridViewRow gvr = e.Row;
GridView gv = (GridView)sender;
DataTable dt = (DataTable)gv.DataSource;
int col=0;
switch(gvr.RowType)
{
case DataControlRowType.DataRow:
col=0;
foreach(DataControlFieldCell cell in gvr.Cells)
{
switch(col)
{
case 0:
cell.CssClass += " purpleBG center"; break;
case 5:
cell.CssClass += " operatorEntryBG center"; break;
default:
cell.CssClass += " tableCell"; break;
}
++col;
}
break;
}
}