简体   繁体   English

AspxGridView中的AspxComboBox

[英]AspxComboBox in AspxGridView

I've been struggling to find a simple example or guidance to my problem. 我一直在努力寻找解决问题的简单示例或指南。 Basically, I have one dataset. 基本上,我有一个数据集。 This table has three columns, 该表有三列,

  • Document Name (string) 文件名称(字串)
  • Document Owner (string) 文档所有者(字符串)
  • Permission (int) 权限(int)

I want to bind this DataTable to a AspxGridView. 我想将此数据表绑定到AspxGridView。 However, I want the final column to be bound to a AspxComboBox so that: 但是,我希望将最后一列绑定到AspxComboBox,以便:

  • If Permission = 1 then bind ComboBox with item A 如果Permission = 1,则将ComboBox与项A绑定
  • If Permission = 2 then bind ComboBox with items A and B 如果Permission = 2,则将ComboBox与项目A和B绑定
  • If Permission = 3 then bind ComboBox with items A, B and C 如果Permission = 3,则将ComboBox与项目A,B和C绑定

How can I achieve this? 我该如何实现? A lot of the samples I've found talk about the AspxGridView being in edit mode. 我发现的许多示例都谈到了AspxGridView处于编辑模式。 The point here is that I'm not actually editing the grid. 这里的要点是我实际上并没有在编辑网格。 All I want to do is do a postback on ComboBox change to do some action. 我要做的就是在ComboBox更改上执行回发操作。

Just bind through SelectedValue property of dropdownList. 只需通过dropdownList的SelectedValue属性进行绑定。 Check below sample 检查以下样品

Aspx
<asp:GridView ID="gvTest" runat="server" AutoGenerateColumns="False" 
    onrowdatabound="gvTest_RowDataBound">
<Columns>
    <asp:TemplateField HeaderText="Serial No."><ItemTemplate><%# Container.DataItemIndex+1 %></ItemTemplate></asp:TemplateField>
    <asp:TemplateField HeaderText="Fruits" ><ItemTemplate><asp:DropDownList runat="server" ID="ddlFruits" SelectedValue='<%# Bind("FruitID") %>'   >
        <asp:ListItem Value="1">Apples</asp:ListItem>
        <asp:ListItem Value="2">Pineapples</asp:ListItem>
        <asp:ListItem Value="3">Banana</asp:ListItem>
        </asp:DropDownList></ItemTemplate> </asp:TemplateField>
</Columns>
</asp:GridView>

C# C#

protected void Page_Load(object sender, EventArgs e)
    {   
        gvTest.DataSource = GetData();
        gvTest.DataBind();
    }

    private DataTable GetData()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("FruitID"));
        for (int i = 0; i < 3; i++)
        {
            DataRow dr=dt.NewRow();
            dr["FruitID"] = i + 1;
            dt.Rows.Add(dr);
        }
        return dt;
    }

Editable combo box in grid display (non-editing) mode: 网格显示(非编辑)模式下的可编辑组合框:

<dx:GridViewDataColumn>
    <DataItemTemplate>
        <dx:ASPxComboBox runat="server" AutoPostBack="True" ...></dx:ASPxComboBox>
    </DataItemTemplate>
</dx:GridViewDataColumn>

ASPxEdit.AutoPostBack ASPxEdit.AutoPostBack
GridViewDataColumn.DataItemTemplate GridViewDataColumn.DataItemTemplate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM