0

私は次のセットアップを持っています

ASPX:

<asp:GridView runat="server" ID="gridRepresentatives" AllowPaging="True" DataKeyNames="Id" OnRowCommand="BtnSubmitCommand" OnRowCreated="GridRepresentativesCreated" CssClass="grid" AutoGenerateColumns="False" Width="100%" EmptyDataText="You don't have rights to manage any organisations.">
    <Columns>
        <asp:BoundField DataField="Position" HeaderText="Position"/>
        <asp:BoundField DataField="Name" HeaderText="Name"/>
        <asp:BoundField DataField="Address" HeaderText="Address"/>
        <asp:TemplateField HeaderText="Roles">
            <ItemTemplate>
                <asp:DropDownList runat="server" ID="dropdownRoles" DataMember="Roles" Width="205px">    
                </asp:DropDownList>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Action">
            <ItemTemplate>
                <asp:DropDownList runat="server" ID="dropdownActions" Width="100px">
                    <asp:ListItem Text="Edit" Value="0"></asp:ListItem>
                    <asp:ListItem Text="Remove" Value="1"></asp:ListItem>
                </asp:DropDownList>
                <asp:Button runat="server" CommandName="Submit" ID="btnSubmit" Text="Go"/>
            </ItemTemplate>
            <ItemStyle CssClass="grid-actions"></ItemStyle>
        </asp:TemplateField>
    </Columns>
    <AlternatingRowStyle CssClass="alternate"></AlternatingRowStyle>
</asp:GridView>

コードビハインド:

 var client = new RepresentativeManagementServiceClient();
            try
            {
                IEnumerable<Representative> representatives =     client.ListRepresentatives("01", _organisationId, role);
                gridRepresentatives.DataSource = representatives;
                gridRepresentatives.DataBind();
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text = ex.Message;
                return;
            }
            finally
            {
                client.Close();
            }

gridview は、公開プロパティのセットとして持つ Type Represenative の IEnumerable にバインドします。内部の IEnumerable Roles プロパティを、グリッドビュー テンプレート フィールド内のドロップダウン リストにバインドしたいと考えています。Datamember をプロパティ (ロール) の名前に設定しようとしましたが、バインドせず、エラーをスローしません。これどうやってするの?

4

2 に答える 2

2

そのドロップダウンのデータ ソースをバインドします。

<asp:TemplateField HeaderText="Roles">
    <ItemTemplate>
        <asp:DropDownList runat="server" ID="dropdownRoles" DataSource='<%# Eval("Roles") %>' Width="205px">    
        </asp:DropDownList>
    </ItemTemplate>
</asp:TemplateField>
于 2013-06-17T16:54:16.540 に答える