I have some troubles with ASPxGridLookup
.
For addition ASPxGridLookup
in a detail we create a similar code
<dx:ASPxGridView ID="gvTable" ClientInstanceName="grid" runat="server" DataSourceID="dataSource"
AutoGenerateColumns="false" Width="100%" KeyFieldName="ID">
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0">
<EditButton Visible="true" />
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="ID" Caption="ID" Name="ID">
</dx:GridViewDataTextColumn>
<dx:GridViewDataColumn FieldName="ItemID" VisibleIndex="2">
<EditItemTemplate>
<dx:ASPxGridLookup ID="GridLookup" runat="server" SelectionMode="Single" DataSourceID="dataSource1"
KeyFieldName="ID" Width="250px" TextFormatString="{0}" MultiTextSeparator=", " Value='<%# Bind("ItemID") %>'
AutoGenerateColumns="true">
<GridViewProperties>
<Settings ShowFilterRow="True" /开发者_如何学C>
</GridViewProperties>
</dx:ASPxGridLookup>
</EditItemTemplate>
</dx:GridViewDataColumn>
<dx:GridViewDataTextColumn FieldName="Title" Caption="Title" Name="Title">
</dx:GridViewDataTextColumn>
</Columns>
<Settings ShowFilterRow="True" ShowFilterRowMenu="true" />
<SettingsEditing PopupEditFormWidth="600px" />
</dx:ASPxGridView>
<asp:SqlDataSource ID="dataSource" runat="server" ConnectionString="<%$ ConnectionStrings:connectionString%>"
SelectCommand="SELECT * FROM [Abbreviation]"></asp:SqlDataSource>
<asp:SqlDataSource ID="dataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:connectionString%>"
SelectCommand="SELECT * FROM [Item]"></asp:SqlDataSource>
For initialisation of combo box we're using the following code
Value = ' <% # Bind ("ItemID") %>'
I have to generate the table and Lookup dynamically from program.
public class LookupTemplate : ITemplate { public ASPxGridLookup lookup { get; set; }
public LookupTemplate(ASPxGridLookup lookup)
{
this.lookup = lookup;
}
#region Implementation of ITemplate
public void InstantiateIn(Control container)
{
container.Controls.Add(lookup);
}
#endregion
}
I generate the table, add columns and into one of them I've to add my lookup.
GridViewDataColumn col = new GridViewDataColumn
{
FieldName = field.Name,
Caption = field.Caption,
Name = field.Name
};
SqlDataSource sqlSource = new SqlDataSource("SELECT * FROM [Item]")
{
ID = "dataSource1";
};
dataSources.DataSources.Add(sqlSource);
ASPxGridLookup lookup = new ASPxGridLookup
{
SelectionMode = GridLookupSelectionMode.Single,
KeyFieldName = "ID",
AutoGenerateColumns = true
};
lookup.GridViewProperties.Settings.ShowFilterRow = true;
lookup.TextFormatString = "{0}";
lookup.Value = "Value='<%# Bind(\"ItemId\") %>'";
LookupTemplate template = new LookupTemplate(lookup);
col.EditItemTemplate = template;
gvTable.Columns.Add(col);
When the user clicks on edit I get post-back event. I form all dynamically again and I do the sane actions (I bring all data in viewstate and then I take therefrom) But at opening of details combo box remains empty ( without value of a field from a line). If I try to open combo box - I'm receiving the necessary table.
How to bind value in ASPxGridLookup
combo box?
It looks like you posted the same question in the http://community.devexpress.com/forums/t/102088.aspx thread. Since you are providing a sample project, I suggest that you forward this request to Support Team (because the http://community.devexpress.com/forums/ – is the Peer-to-Peer Support Forums for the DX users).
精彩评论