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

Access RadGrid's EditIndex in button click event

3 Answers 269 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Neelima
Top achievements
Rank 1
Neelima asked on 20 Oct 2010, 06:49 PM
Hi

How do I get radGrids EditIndex or a row that is in editmode in a button click event handler that is outside the RadGrid?

Thanks!!
Neelima
Protected Sub btnOK_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnOK.Click
  
 Dim phone As String = String.Empty
 Dim row As GridEditableItem ' How to get the row that is in editmode?
 phone = DirectCast(row.FindControl("txtPhone"), TextBox).Text
  
End Sub


     <telerik:RadGrid ID="RadgridDestination" runat="server"
     AllowSorting="True"  ShowGroupPanel="True" 
     AutoGenerateColumns="False"
          Skin="Sunset" AllowPaging="True" GridLines="None">
  
        <GroupingSettings ShowUnGroupButton="True"  />
        <ClientSettings AllowDragToGroup="True" allowcolumnsreorder="True" 
            columnsreordermethod="Reorder" reordercolumnsonclient="True" >
        </ClientSettings>
          
  
<MasterTableView EditMode="InPlace" DataKeyNames="Destination_ID" GroupLoadMode="Client" >
<CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
  
    <Columns>
      
        <telerik:GridEditCommandColumn ButtonType="ImageButton">
        </telerik:GridEditCommandColumn>
          
         <telerik:GridButtonColumn CommandName="Select" Text="Select"  ButtonType="ImageButton"
            UniqueName="column1" ImageUrl="Images/Home-Edit.gif">
        </telerik:GridButtonColumn>  
                              
                              
                <telerik:GridBoundColumn DataField="Destination_ID"  
            HeaderText="Destination_ID" visible="False" UniqueName="Destination_ID" />
'
'
'
'
 <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" 
            Text="Delete" UniqueName="Delete">
        </telerik:GridButtonColumn>
                      
            </Columns>
           <EditFormSettings>
<EditColumn UniqueName="EditCommandColumn1"></EditColumn>
</EditFormSettings>
</MasterTableView>
  
  
    </telerik:RadGrid>
  
<asp:Button ID="btnOK" runat="server"  CausesValidation="false" Text=" OK " /> 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Oct 2010, 06:52 AM
Hello Neelima,

You can try the following code snippet to access the edit row from an external button click.

 protected void btnOK_Click(object sender, EventArgs e)
    {
GridEditableItem item = (GridEditableItem)RadgridDestination.MasterTableView.GetItems(GridItemType.EditItem)[0];
    }

Thanks,
Princy.
0
Neelima
Top achievements
Rank 1
answered on 22 Oct 2010, 06:26 AM
Hi Princy,

Actually I have this button 'btnOK' in a ModalPopup window. When  the update button on the RadGrid is clicked, this ModalPopup window popsup. 
In the  btnOK click event I'm not able to capture the editedRow as the RadGrid is already back to its normal mode (from editmode).
I'm using Advanced DataBinding (NeedDataSource method).

Is there a way to keep the row in Editmode until btnOK is clicked.

Thanks
Neelima
0
Princy
Top achievements
Rank 2
answered on 22 Oct 2010, 10:19 AM
Hello Neelima,

You can achieve this by not closing the edit form after updation. Then inside the Click event of 'btnOK', close the edit form. Check out the sample code below.

C#:
int rowindex = -1;
protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
{
    GridEditableItem editItem = (GridEditableItem)e.Item;
    rowindex = editItem.ItemIndex;
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (rowindex >= 0)
    {
        RadGrid1.MasterTableView.Items[rowindex].Edit = true;
        RadGrid1.MasterTableView.Rebind();
    }
}
protected void btnOK_Click(object sender, EventArgs e)
{
    RadGrid1.MasterTableView.ClearEditItems(); //closing edit form
    RadGrid1.MasterTableView.Rebind();
    rowindex = -1;
}

Thanks,
Princy.
Tags
Grid
Asked by
Neelima
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Neelima
Top achievements
Rank 1
Share this question
or