[英]How to set selected value of an asp:dropdownlist in a AspxGridView
I checked around for a solution to this and the solutions I have found use a SqlDataSource, but I am not populating it that way. 我检查了一个解决方案,发现的解决方案使用了SqlDataSource,但我不是用这种方式填充它。 I have the items hardcoded in the html, and the grid is binded to a dataset.
我将项目硬编码在html中,并将网格绑定到数据集。 This is my first time using dropdowns in any type of grid and I am getting confused.
这是我第一次在任何类型的网格中使用下拉菜单,这让我感到困惑。 I tried using the ComboBoxColumn in the item template but was having major issues on trying to find the combobox control, so I went with the normal asp:DropDownList.
我尝试在项目模板中使用ComboBoxColumn,但是在尝试查找组合框控件时遇到了主要问题,因此我选择了常规的asp:DropDownList。 Incase you're wondering, I can't even find that control without it returning null.
万一您想知道,如果没有返回null,我什至找不到该控件。
So as the grid gets populated I need to set the selected value of the dropdowns. 因此,随着网格的填充,我需要设置下拉菜单的选定值。
The markup is 标记是
<dx:ASPxGridView ID="xgvEdit" runat="server" Width="100%">
<Columns>
<dx:GridViewDataColumn FieldName="roleID" Caption="ID" Visible="false"></dx:GridViewDataColumn>
<dx:GridViewDataColumn FieldName="modulID" Caption="Document/UseCase (Right Object)">
<Settings AutoFilterCondition="Contains" />
</dx:GridViewDataColumn>
<dx:GridViewDataColumn FieldName="right_level" Caption="Right Level">
<DataItemTemplate>
<asp:DropDownList ID="ddRightLevel" runat="server" AutoPostBack="false">
<asp:ListItem Text="No Right" Value="0" />
<asp:ListItem Text="Read" Value="1" />
<asp:ListItem Text="Write" Value="2" />
<asp:ListItem Text="Execute" Value="3" />
</asp:DropDownList>
</DataItemTemplate>
</dx:GridViewDataColumn>
<dx:GridViewDataColumn FieldName="comments" Caption="Comments">
<Settings AutoFilterCondition="Contains" />
</dx:GridViewDataColumn>
</Columns>
I suppose that this is custom GridView which inherits asp:GridView
. 我想这是自定义GridView,它继承了
asp:GridView
。 You need to add event 您需要添加事件
OnRowDataBound="Grid_RowDataBound"
In Code behind: 在后面的代码中:
protected void ProductGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.DataItem == null)
return;
DropDownList ddl= e.Row.FindControl("ddRightLevel") as DropDownList;
//do stuff
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.