简体   繁体   English

如何在AspxGridView中设置asp:dropdownlist的选定值

[英]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.

相关问题 ASP如何在详细信息视图中绑定下拉列表的选定值 - ASP How to bind the selected value of a dropdownlist in detailsview 如何在dropdownlist mvc中设置所选值 - how to set the selected value in dropdownlist mvc 如何在MVC中正确设置Dropdownlist Selected Value - How to set Dropdownlist Selected Value correctly in MVC 如何在DropDownList编辑模板上设置选定的值? - How to set selected value on DropDownList edit template? 如何在aspxgridview devexpress中获取所选行的值 - how to get value of selected row in aspxgridview devexpress 根据从asp:DropDownList中选择的值设置输入文本 - set input text based on selected value from asp:DropDownList 设置在ASP.NET MVC中的“编辑”期间选择的下拉列表值 - Set dropdownlist value selected during Edit in ASP.NET MVC 如何从一个数据源填充ASP.NET DropDownList并从另一个数据源设置所选值? - How to populate an ASP.NET DropDownList from one datasource and set the selected value from another? 在 ASP.Net 中的 GridView EditItemTemplate 中设置 DropDownList 选定值 - Set DropDownList Selected Value in GridView EditItemTemplate in ASP.Net 如何在asp.net mvc 4中设置下拉列表的选定值 - How can I set the selected value of dropdownlist in asp.net mvc 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM