E.Item.DataItem is null in ItemCommand of RadGrid

3 posts, 0 answers
  1. Nannu
    Nannu avatar
    7 posts
    Member since:
    Dec 2006

    Posted 23 Aug 2011 Link to this post

    Im trying to Bind datasource to datagrid. On Click of refresh button on Grid,
                    <table width="100%">
                            <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;

     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

  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 23 Aug 2011 Link to this post


    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.

    Jayesh Goyani
  3. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 29 Apr 2013 Link to this post


    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.


Back to Top