I am required to use the DevExpress ASPxGridView. I have a datasource Object which returns two columns of importance, ObjectType and ObjectID. ObjectType can be Dogs or Cats. ObjectID is a int value giving the ID of the Dog or Cat. Hopefully this makes sense. The ObjectID is selected by either the Dog table or the Cat table, they are indendent tables so I can't join them in any way.
So basically it looks like this:
Object table: ObjectType varchar ("Dogs" or "Cats") ObjectID int
Dogs Table ID int Name varchar
Cats table ID int Name varchar
I have been able to write the appropriate objectType by a combobox, and the ObjectID by using two controls, cbDogs and cbCats, which are populated by datasources.
What I can't figure out is when I edit the ASPxGridView, how can I show in cbCats or cbDogs the object value. For example if ObjectType is Cats and ObjectID is 1 then I want to show in cbCats the name that corresponds with ID of 1. What I really want to do is something like this. Obviously this code does not work at all.
if (ObjectType = "Cats")
{
object objID = grid.GetRowValuesByKeyValue(e.KeyValue, "ObjectID");
string objIDstr = objID.ToString()
cbCats.SelectedValue = objIDstr // or something like this
}
If this is helpful here is the declaration for cats in the aspx page.
<dx:GridViewDataComboBoxColumn Caption="Cat Name" FieldName="CatID" Name="CatName" Visible="false">
<PropertiesComboBox DataSourceID="dsCatName" TextField="Name" ValueField="ID" ValueType="System.Int32">
</PropertiesComboBox>
<EditItemTemplate>
<dx:ASPxComboBox ID="cbCat" runat="server" DataSourceID="dsCatName" TextField="Name" ValueField="ID"
Value='<%# Bind("CatID") %>' AutoPostBack="false" ValueType="System.Int32" > </dx:ASPxComboBox>
</EditItemTemplate>
</dx:GridViewDataComboBoxColumn>
If I have understood your question correctly, all you have to do is:
if(ObjectType=="Cats")
{
Int32 objID = Convert.toInt32(grid.GetRowValuesByKeyValue(e.KeyValue, "ObjectID"));
cbCats.Items[cbCats.Items.FindByValue(objId)].selected = true;
}
As a precaution you can put a check like this:
if(cbCats.Items.FindByValue(objID) != null)
{
cbCats.Items[cbCats.Items.FindByValue(objId)].selected = true;
}
else
{
cbCats.Items[0].selected = true;
}
I hope it will give you your desired results.