This is a migrated thread and some comments may be shown as answers.

Wrong row open for editing when editing the 2 page record(paging)

2 Answers 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ajay
Top achievements
Rank 1
Ajay asked on 29 Aug 2012, 04:00 AM
HI ,

I am using the Rad grid which is bind dynamically through code from code behind.

1.CRUD operation are performed on UpdateCommand,InsertCommand and DeleteCommand event.

2. I have another event lie need_datasource and itemdatabound event.

4.Paging is true.

When I click on Edit button on first page it works correctly. But when I go to Next or any other page apart from 1 page. it open the wrong record for editing. e.g I click on 2nd record on page 2 than it open the other recrord to edit.

Flow of event.
Click on Edit -> fires Need_Datasource event (which don't have RadGrid.Databind()).-> itemDataBound event is called -> it fetching the wrong datakey here. Below is the code of itemdatabound

if ((e.Item is GridEditableItem || e.Item is GridDataItem) && e.Item.IsInEditMode)
            {
                clsPEstimateLineItem objEstimatelineItem = new clsPEstimateLineItem();
                GridEditableItem editForm = (GridEditableItem)e.Item;
               
                objEstimatelineItem.LineItemId = clsFilter.IntNullFilter(item.GetDataKeyValue("LineItemId").ToString());
                //objEstimatelineItem.LineItemId = clsFilter.IntNullFilter(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["LineItemId"]);
                DataSet dslineItem = objBEstimateLineItem.GetEstimateLineItemById(objEstimatelineItem);

               RadTextBox txtDescription = editForm.FindControl("txtDescription") as RadTextBox;
                string Description = dslineItem.Tables[0].Rows[0].Field<string>("Description");
                txtDescription.Text = Description.ToString();
       }

Thanks
Ajay

2 Answers, 1 is accepted

Sort by
0
Ajay
Top achievements
Rank 1
answered on 03 Sep 2012, 03:43 AM
Hi Telerik Support,

Is there anyone in Telerik Support, who will answer the above question.

Ajay
0
Jayesh Goyani
Top achievements
Rank 2
answered on 03 Sep 2012, 06:16 AM
Hello,

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" OnItemDataBound="RadGrid1_ItemDataBound"
           OnNeedDataSource="RadGrid1_NeedDataSource" AllowPaging="true" PageSize="2">
           <MasterTableView Name="Parent" DataKeyNames="ID">
               <Columns>
                   <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                   </telerik:GridBoundColumn>
                   <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
               </Columns>
           </MasterTableView>
       </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
   {
       dynamic data = new[] {
               new { ID = 1, Name ="Name1",path="1.jpg"},
               new { ID = 2, Name = "Name2",path="2.jpg"},
               new { ID = 3, Name = "Name3",path="3.jpg"},
                new { ID = 4, Name = "Name4",path="2.jpg"},
               new { ID = 5, Name = "Name5",path="3.jpg"}
           };
       RadGrid1.DataSource = data;
   }
 
   
   protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item.IsInEditMode && e.Item is GridEditableItem)
       {
           GridEditableItem item = e.Item as GridEditableItem;
           string strID = item.GetDataKeyValue("ID").ToString();
           // Access your DataKey here
       }
   }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Ajay
Top achievements
Rank 1
Answers by
Ajay
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or