Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all, i am using infragistics grid to insert,edit.. so far i was able to complete insert part. But now I am stuck with updating part.. I will post below my codes and can some one help me to figure out this issue..

<<pre lang="xml">ig:WebDataGrid
                                                ID="MeterReadingDataGrid" runat="server" Height="205px" Width="794px"
                                                style="margin-bottom: 11px" onrowadding="WebDataGrid1_RowAdding"
                                                DataKeyFields="MachineID" onrowupdated="MeterReadingDataGrid_RowUpdated"
                                                onrowupdating="MeterReadingDataGrid_RowUpdating"
                                                 EnableAjaxViewState="False"  >
                                                <Behaviors>
                                                    <ig:ColumnMoving>
                                                    </ig:ColumnMoving>
                                                    <ig:ColumnResizing>
                                                    </ig:ColumnResizing>
                                                    <ig:Selection CellClickAction="Row" RowSelectType="Single">
                                                    </ig:Selection>
                                                    <ig:Activation>
                                                    </ig:Activation>
                                                    <ig:EditingCore Enabled="true" AutoCRUD="false">
                                                        <Behaviors>
                                                            <ig:CellEditing Enabled="true">
                                                            <EditModeActions MouseClick="Single" />
                                                            <ColumnSettings>
                                                            <ig:EditingColumnSetting ColumnKey="MachineDescription" EditorID="MachineID" />
                                                            <ig:EditingColumnSetting ColumnKey="LastDayMeterReading" EditorID="MachineID" />
                                                            <ig:EditingColumnSetting ColumnKey="CurrentDayMeterReading" EditorID="MachineID" />
                                                            </ColumnSettings>
                                                            </ig:CellEditing>
                                                            <ig:RowAdding>
                                                            </ig:RowAdding>
                                                        </Behaviors>

                                                    </ig:EditingCore>
                                                    <ig:RowSelectors>


                                                    </ig:RowSelectors>
                                                </Behaviors>




                                            </ig:WebDataGrid></pre>


and code behind

C#
protected void MeterReadingDataGrid_RowUpdating(object sender, Infragistics.Web.UI.GridControls.RowUpdatingEventArgs e)
   {



       int id;
       string machine = string.Empty;
       decimal lastDayReading = 0.0M;
       decimal currentDayReading = 0.0M;


       id = System.Convert.ToInt16(e.Values["MachineID"].ToString());
       machine = machine = e.Values["MachineDescription"].ToString();
       lastDayReading = System.Convert.ToDecimal(e.Values["LastDayMeterReading"].ToString());
       currentDayReading = System.Convert.ToDecimal(e.Values["CurrentDayMeterReading"].ToString());

       SqlConnection con = new SqlConnection(connectionString);
       SqlCommand cmd = new SqlCommand("EditDailyElectricityDetails", con);
       con.Open();
       cmd.CommandType = CommandType.StoredProcedure;
       cmd.Parameters.AddWithValue("id", id);
       cmd.Parameters.AddWithValue("lastdayreading", lastDayReading);
       cmd.Parameters.AddWithValue("currentdayreading", currentDayReading);
       cmd.ExecuteNonQuery();
       con.Close();
       DisplayGrid();


   }
Posted
Updated 6-Nov-13 17:23pm
v2
Comments
ArunRajendra 6-Nov-13 23:22pm    
What to mean by stuck? Are you getting exception?
Member 10327058 7-Nov-13 0:05am    
[MissingRecordException]: Requested record cannot be found by key

Common Causes:

-The data key field(s) is being edited causing the record not to be found when trying to update

-Not rebinding the grid when there are updates to be commited (assuming DataViewState is disabled in this case)
-for instance if the grid is bound on !IsPostback

-While a user is editig a particular row in the grid, another user deletes the record from the database. On posting back, the grid is rebound tot the updated datasource which no longer contains the record, resulting the exception

-Changing completely or filtering the grid's datasource before all CRUD operations are carried out - this is quite common when using other controls on the page to do this. This is partly due to the fact that control events such as SelectIndexChanged for a dropdownlist or click for button fire before the update events.Changing the grid's source should in such cases by delayed for later
Member 10327058 7-Nov-13 0:07am    
This is what i get. im confused little bit ..
ArunRajendra 7-Nov-13 0:44am    
Ok just to reconfirm you are facing concurrency issue? i.e. data is modified / deleted by user 2 during the time data was read and updated by user 1.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900