protected void radGrid_RowDrop(object sender, GridDragDropEventArgs e)
{
foreach(GridDataItem gridItem in this.radGrid.MasterTableView.Items)
{
//do stuff...
}
foreach (GridDataItem draggedItem in e.DraggedItems)
{
//do stuff
}
}
Edit - this grid is in a radajax panel if it makes any difference -
4 Answers, 1 is accepted
It seems that in your case the dragged items/the Items collection of the grid are empty due to some reason and you receive the exception. Can you trace the reason for that or paste your grid declaration along with its code-behind in order to advice you further?
Kind regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Here are the declarations:
<telerik:RadGrid ID="rGrid" runat="server" Width="100%" AllowMultiRowSelection="true"
EnableEmbeddedSkins="false" Skin="Black" ImagesPath="../Skins/Black/Grid" AutoGenerateColumns="false"
GridLines="Both" ShowHeader="true" OnRowDrop="rGrid_RowDrop">
<ClientSettings AllowRowsDragDrop="true">
<Selecting AllowRowSelect="true" EnableDragToSelectRows="true" />
</ClientSettings>
<MasterTableView Width="97%" CommandItemDisplay="None" AutoGenerateColumns="false"
DataKeyNames="ID" TableLayout="Auto" HeaderStyle-HorizontalAlign="Center"
HeaderStyle-VerticalAlign="Middle" HeaderStyle-Wrap="false" NoMasterRecordsText="No items.">
<Columns>
<telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID"
Visible="false">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn DataField="Checked" HeaderText="Show" UniqueName="Checked"
Visible="true" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" ItemStyle-Height="20px"
HeaderStyle-Height="30px">
<ItemTemplate>
<asp:CheckBox runat="server" ID="displayCheckbox" Checked='<%# DataBinder.Eval(Container, "DataItem.Checked") %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name"
Visible="true" ItemStyle-Wrap="true" ItemStyle-HorizontalAlign="Left" ItemStyle-VerticalAlign="Middle"
HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" ItemStyle-Height="20px"
HeaderStyle-Height="30px" ReadOnly="true">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
Function to load grid data (it's in a radajax panel):
private void displaySettingsPanelLoad(IPostBackEventHandler source, string eventArgs)
{
DataTable dTable = Function here to get table, I know for sure this works...
this.rGrid.DataSource = metadataTable;
this.rGrid.DataBind();
}
I do have another function to handle updates the grid checkboxes in the code-behind. This is working fine.
Try binding the Grid using AdvanceDataBinding techniques. Go through the following demo link for more details.
Advanced data-binding
Thanks
Princy.