Wolf
Wolf

Reputation: 170

how to bind a datagrid to a devexpress comboBox

ok folks i have a populated datagrid and my comboBox is populated all i need now is the knowledge on how to bind the datagrid to my AspxcomboBox

i have done research on this i find precious little that makes sense to me in my situation. if you guys need to see my code i will provide it but i would rather not if possible.Just to clarify i did do research on this so i am not just asking for comfort-sake or convenience. i knew how to do this once upon a time but vb has ruined me any help or advice would be appreciated i am asking for assistance so keep the votedowns to a minimum

Upvotes: 0

Views: 1313

Answers (2)

Ando
Ando

Reputation: 26

You should follow the steps: 1- Define a asp:ObjectDataSource ID="dgDataSource" for your datagrid. 2- Define a asp:ObjectDataSource ID="cbDataSource" for your ComboBox. NOTE: Each of these 2 data sources are connected to a 2 different Models.

<dx:ASPxGridView ID="myListGridView" ClientInstanceName="myListGridView" DataSourceID="dgDataSource"
    runat="server" AutoGenerateColumns="False" KeyFieldName="**field1Ofdg**"
    OnRowUpdated="myListGridView_RowUpdated">

<Columns>
    <dx:GridViewDataColumn FieldName="**field1Ofdg**" Caption="Code" Width="30%" >
        </dx:GridViewDataColumn>
    <dx:GridViewDataComboBoxColumn FieldName="**field2Ofdg**" ReadOnly="false" >  
        <PropertiesComboBox DataSourceID="cbDataSource" TextField="**LabelOfcb**" ValueField="**IdOfcb**"  >
        </PropertiesComboBox>
    </dx:GridViewDataComboBoxColumn>                   
</Columns>
</dx:ASPxGridView>

thes are the definitions for your data sources:

<asp:ObjectDataSource ID="dgDataSource" runat="server" SelectMethod="GetMyDataForGridFunction" 
        UpdateMethod="UpdateDataForGridFunction" TypeName="namespace1"></asp:ObjectDataSource>

     <asp:ObjectDataSource ID="cbDataSource" runat="server" SelectMethod="GetMyDataForComboBoxFunction"
         TypeName="namespace2"></asp:ObjectDataSource>

NOTE: field1Ofdg and field1Ofdg are properties of Model1 Model of the grid. LabelOfcb and IdOfcb are properties of Model2 model of the ComboBox.

Keep me updated if it works fine to you :)

Best Regards, ANDOURA

Upvotes: 0

Mych
Mych

Reputation: 2553

Have a look at this... it has a simple layout and uses a dropdown rather than combo but can be adapted. If you run into any problems then let us know.... but supplying some code would be easier.

http://www.aspsnippets.com/Articles/Filter-GridView-with-DropDownList-using-FilterExpression-in-SqlDataSource-in-ASPNet.aspx

Upvotes: 1

Related Questions