我有以下设置
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 绑定到具有一组公共属性的 Represenative 类型的 IEnumerable。我想将内部的 IEnumerable Roles 属性绑定到 gridview 模板字段内的下拉列表。我试图将 Datamember 设置为属性(角色)的名称,但它只是不绑定并且不会引发任何错误。我怎样才能做到这一点?