Hi i have a problem with the gridview in edit mode.
I have loaded the gridview from multiple datasources (some are just lookup tables)
But when i click edit on a row, and not change a certain value and try to access it using e.OldValues["columnName"] it gives me the string name and not the lookup ID, but if i change that data to something else then it works and gives me the ID instead of the name. Code below:
Load data from lookuptable and fill the grid with value=ID and text=Produkt
<dx:GridViewDataComboBoxColumn FieldName="Scoring" VisibleIndex="5">
<PropertiesComboBox Spacing="0" ValueType="System.Int32" DataSourceID="dsScoringType" ValueField="id" TextField="Produkt">
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
The SQLDataSource that loads the lookup tables information
<asp:SqlDataSource ID="dsScoringType" runat="server"
ConnectionString="<%$ ConnectionStrings:halldbConnectionString %>"
SelectCommand="SELECT [id], [Produkt] FROM [selScoringType]"
OldValuesParameterFormatString="original_{0}">
</asp:SqlDataSource>
The GridViews RowUpdating event
protected void custGridview_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
// If this hasent been changed the value will be a string with the name
// If it has been changed though i get the correct data, that is the ID and not the name
var scoringType = e.NewValues["Scoring"];
var scoringType2 = e.OldValues["Scoring"];
}
Why is this behaving like this?
Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.
Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.
Hello Andreas:
As a rule, this problem occurs when the item with the current cell value is not presented in the Items collection of the ASPxComboBox.
You can check this condition in the server-side CellEditorInitialize event:
protected void ASPxGridView1_CellEditorInitialize(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewEditorEventArgs e) { if (e.Column.FieldName == "Scoring") { object val = ASPxGridView1.GetRowValues(e.VisibleIndex,"Scoring"); ASPxComboBox cmb = e.Editor as ASPxComboBox; ListEditItem itemToSelect = cmb.Items.FindByValue(val); } }
If the itemToSelect variable returns null, check that you have set the ValueType property correctly (it should be the same as the type of data in the ValueField).
If these suggestions do not help, please provide a sample illustrating the issue for more detailed research.
Hi and thank you for trying to help!
I will attach a sample that will show you the error i have, indeed the code that you provided gave me a null result. But i thought i loaded this with the following line:
<PropertiesComboBox Spacing="0" ValueType="System.Int32" DataSourceID="dsScoringType" ValueField="id" TextField="Produkt">
If you press edit and the update with no changes you will see that the e.OldValues["Country"] has a string value, if you do the same but change country you get the correct countryID instead.
Best regards,
Andreas
Hi
If i look at the following demo
http://demos.devexpress.com/ASPxGridViewDemos/GridEditing/CascadingComboBoxes.aspx
I see there is alot of code behind doing just this. Am i really supposed to write all this code for every combobox that has lookup tables values?
Hi Andreas,
Thank you for sending us your sample. It seems that your SQL Server (700) is newer than mine (663), so I cannot use your database. However, I have created an in-memory datasource based on your data. I am afraid my attempts to reproduce the issue have been unsuccessful. Would you please check how the attached project operates? If it operates well, reproduce this issue using it and send the project back to us. Alternatively, you can provide your complete project. We will do our best to help you.
In addition, I have noticed that you are using the Country string value to synchronize two database tables. By design, to make GridViewDataComboBoxColumn operate properly, the GridViewDataComboBoxColumn.FieldName and PropertiesComboBox.ValueField values should be equal, but not TextField. It is a common practice to use a number value for this purpose.
Thanks,
Marion
I got the help i needed