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

Grid is not refreshed after ItemCommand

3 Answers 249 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rajesh
Top achievements
Rank 1
Rajesh asked on 23 Sep 2015, 03:03 AM

 Grid is not refreshed after ItemCommand event

 

 

Protected Sub Parts_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles Parts.ItemCommand
If e.CommandName = "DeleteInventory" Then
Dim filename As String = _uploadSystemPath & "tree.xml"
Dim XMLDoc As XDocument = XDocument.Load(_uploadSystemPath & "tree.xml")
XMLDoc.Root.Elements("Node")(e.Item.ItemIndex).Remove()
XMLDoc.Save(filename)
XMLBookBuilderSource.DataFile = _uploadSystemPath & "tree.xml"
Parts.DataSource = XMLBookBuilderSource
Parts.DataBind()
End If
End Sub

3 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 23 Sep 2015, 11:57 AM
Hi Rajesh,

From the provided code it seems that you are using simple data binding for RadGrid. That is, the grid is bound via the DataBound() method. Note that this type of binding us suitable only for the most simple scenarios.

In most cases it is recommended to use advanced data binding. You can either use declarative datasource or handle the NeedDataSurce event. Check out the following resources that elaborate in more detail on both approaches.


With this approach if you need to rebind RadGrid explicitly you should call Rebind().

Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Rajesh
Top achievements
Rank 1
answered on 23 Sep 2015, 02:42 PM

 Hi Viktor,

I used the below code still the Needdatasource is not calling after the Itemcommand.

  

Protected Sub Parts_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles Parts.ItemCommand
If e.CommandName = "DeleteInventory" Then
Dim filename As String = _uploadSystemPath & "tree.xml"
Dim XMLDoc As XDocument = XDocument.Load(_uploadSystemPath & "tree.xml")
XMLDoc.Root.Elements("Node")(e.Item.ItemIndex).Remove()
XMLDoc.Save(filename)
'XMLBookBuilderSource.DataFile = _uploadSystemPath & "tree.xml"
'Parts.DataSource = XMLBookBuilderSource
'Parts.DataBind()
Parts.DataSource = Nothing
Parts.Rebind()
End If
End Sub

Protected Sub Parts_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs) Handles Parts.NeedDataSource
If File.Exists(_uploadSystemPath & "tree.xml") Then
XMLBookBuilderSource.DataFile = _uploadSystemPath & "tree.xml"
Parts.DataSource = XMLBookBuilderSource
End If
End Sub

  

<telerik:RadGrid ID="Parts" ClientIDMode="Static" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" GridLines="None" ShowStatusBar="True" CssClass="Parts" ClientSettings-AllowDragToGroup="true" ClientSettings-AllowRowsDragDrop="true">
<ClientSettings AllowRowsDragDrop="true">
<Selecting AllowRowSelect="True" EnableDragToSelectRows="false" />
</ClientSettings>
<MasterTableView Name="PartsTableView" DataKeyNames="InventoryID" AllowSorting="True" NoDetailRecordsText="No Items" HierarchyLoadMode="ServerBind"
NoMasterRecordsText="No Items Added" CommandItemDisplay="Bottom" EditMode="Batch">
<CommandItemSettings ShowAddNewRecordButton="false" />
<BatchEditingSettings EditType="Cell" />
<DetailTables>
<telerik:GridTableView Name="ComponentDetails" Caption="Component Details" DataKeyNames="InventoryID"
runat="server">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="ParentID" MasterKeyField="InventoryID" />
</ParentTableRelation>
<Columns>
<telerik:GridBoundColumn DataField="ParentID" Display="false" UniqueName="ParentID" />
<telerik:GridBoundColumn DataField="InventoryID" HeaderText="InventoryID" ReadOnly="true"
UniqueName="InventoryID" />
<telerik:GridBoundColumn DataField="FormNumber" HeaderText="Form #" UniqueName="FormNumber" />
<telerik:GridBoundColumn DataField="Description" HeaderText="Description" ReadOnly="true"
UniqueName="Description" Display="True" />
</Columns>
</telerik:GridTableView>
</DetailTables>
<Columns>
<telerik:GridTemplateColumn UniqueName="ThumbNail">
<ItemTemplate>
<asp:Image ID="imgThumbNail" runat="server" ImageUrl='<%#Eval("ImageUrl")%>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="InventoryID" UniqueName="FormNumber" Display="false" />
<telerik:GridBoundColumn DataField="Text" HeaderText="Product Code" />
<telerik:GridBoundColumn DataField="Description" Display="false" />
<telerik:GridTemplateColumn UniqueName="Description" HeaderText="Title">
<ItemTemplate>
<asp:Label ID="lblDescription" runat="server" Text='<%#Eval("Description") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtDescription" runat="server" Text='<%#Eval("Description") %>'>
</asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="Type" Display="false" />
<telerik:GridEditCommandColumn ButtonType="ImageButton" EditText="Edit" UniqueName="EditCommandColumn">
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn ButtonType="ImageButton"
CommandName="DeleteInventory" Text="Remove" UniqueName="Delete">
<ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"></ItemStyle>
<HeaderStyle Width="20px"></HeaderStyle>
</telerik:GridButtonColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:XmlDataSource ID="XMLBookBuilderSource" runat="server">
</asp:XmlDataSource>

0
Accepted
Viktor Tachev
Telerik team
answered on 24 Sep 2015, 11:42 AM
Hi Rajesh,


It seems that you are using a declarative DataSource control for RadGrid. In that case you should set the DataSourceID property of RadGrid. Also the NeedDataSource event would not be needed in this scenario. Check out the following article that describes how you can bind RadGrid to a declarative DataSource in more detail.



Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Rajesh
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Rajesh
Top achievements
Rank 1
Share this question
or