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

E.Item.DataItem is null in ItemCommand of RadGrid

2 Answers 588 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nannu
Top achievements
Rank 1
Nannu asked on 23 Aug 2011, 09:35 AM
Hi,
Im trying to Bind datasource to datagrid. On Click of refresh button on Grid,
 <CommandItemTemplate>
                <table width="100%">
                    <tr>
                        <td align="right">
                            <asp:Button ID="btnClearFilters" runat="server" CssClass="rgCancel" CommandName="ClearFilters" /><asp:LinkButton
                                ID="lnkClear" runat="server" CommandName="ClearFilters" Text="Clear Filters"></asp:LinkButton>&nbsp;&nbsp;&nbsp;
                           
                        </td>
                    </tr>
                </table>
            </CommandItemTemplate>


 protected void rgProjects_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
if (e.CommandName == RadGrid.RebindGridCommandName)
                {
                GridDataItem item = (GridDataItem)e.Item;  // Here e.Item is always null
                string documentID = DataBinder.Eval(e.Item.DataItem, "DocumentID").ToString();

                //  string documentID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["DocumentID"].ToString();
                string library = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Library"].ToString();
                string application = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ApplicationName"].ToString();
                string document = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Document"].ToString();

                }
}

Can any1 tell me how to get the Dataitem for current roww

-Mahender

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 23 Aug 2011, 09:55 AM
Hello,

you get every time null Because Rebind command is not fire from particular row .

For example : Update /Select command are fire from particular Row so you can get this row in GridDataItem. 

Please explain your Requirement/Scenario.

Let me know if any concern.

Thanks,
Jayesh Goyani
0
Erik
Top achievements
Rank 2
answered on 29 Apr 2013, 11:39 AM
Hello,

Old post, but came here via Google, so others must come here too...

I agree with Nannu; it is not logical behaviour.

I have a grid that binds to a List of entities (disconnected open access).
Both in the events ItemCommand and UpdateCommand the e.Item.DataItem is Nothing. This is not logical in a Update/Insert/Delete scenario. It would be logical to access the entity, make changes according to edit/insert/delete and rebind so changes are visible in the grid. In my case the save to OpenAccess is done later. (Disconnected entities)

So, the ItemCommand, but most centenary the UpdateCommand / InsertCommand / DeleteCommand events should have a ref to the entity via e.Item.DataItem.

Erik

Tags
Grid
Asked by
Nannu
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Erik
Top achievements
Rank 2
Share this question
or