Find GridDataItem on LinkButton click.

3 posts, 1 answers
  1. Lokesh
    Lokesh avatar
    89 posts
    Member since:
    Jul 2012

    Posted 24 Jul 2012 Link to this post

    Hi Team,
    I have a hierarchical grid in which, in a group header, I am adding a link button control on ItemDataBoundEvent.
    On click of this button, I want to get GridDataItem object so that I can find the values in columns.
    I tried using GridDataItem dItem = rgVoucherSearch.MasterTableView.GetItems(GridItemType.Item)[0] as GridDataItem, but it always returns me the first (0th) DataItem. 
    How can I get the rowindex/groupindex so that I can get the excat row ?

    This is my code behind :

    void lnkOpenVoucher_Command(object sender, CommandEventArgs e)
     {
        LinkButton lnkOpenVoucher = (LinkButton)sender;
        GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)lnkOpenVoucher.NamingContainer;
         string url = string.Empty;
     
                GridDataItem dItem = rgVoucherSearch.MasterTableView.GetItems(GridItemType.Item)[0] as GridDataItem;
     
          if (dItem["AccountJournalEventTypeID"].Text ==                                             GlobalConstants.ACCOUNTJOURNAL_EVENT_TYPE_ID_FOR_CASH_RECEIPT.ToString())
                url = "ManageTransactionPrerview.aspx?LedgerReferenceKey=" + dItem["AccountJournalLedgerReferenceKey"].Text + "&EventTypeID=" + GlobalConstants.ACCOUNTJOURNAL_EVENT_TYPE_ID_FOR_CASH_RECEIPT;
         if (dItem["AccountJournalEventTypeID"].Text == GlobalConstants.ACCOUNTJOURNAL_EVENT_TYPE_ID_FOR_AR_INVOICE.ToString())
                 url = "ManageTransactionPrerview.aspx?LedgerReferenceKey=" + dItem["AccountJournalLedgerReferenceKey"].Text + "&EventTypeID=" + GlobalConstants.ACCOUNTJOURNAL_EVENT_TYPE_ID_FOR_AR_INVOICE;
    }

    Any help appreciated. 
    Thanks,
    Lok..

  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Jul 2012 Link to this post

    Hi Lokesh,

    I suppose you want to access column value in OnCommand event. Here is the sample code.
    C#:

    void lnkOpenVoucher_Command(object sender, CommandEventArgs e)
    {
     LinkButton btn = (LinkButton)sender;
     GridGroupHeaderItem item = (GridGroupHeaderItem)btn.NamingContainer;
     foreach (GridGroupHeaderItem headerItem in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
     {
       if (headerItem.GroupIndex == item.GroupIndex)
       {
         GridItem[] children = headerItem.GetChildItems();
         foreach (GridDataItem child in children)
         {
           GridDataItem dataItem = child as GridDataItem;
           string value = dataItem["UniqueName"].Text;
         }
       }
     }
    }

    Thanks,
    Princy.

  3. Lokesh
    Lokesh avatar
    89 posts
    Member since:
    Jul 2012

    Posted 24 Jul 2012 Link to this post

    Hi Princy,
    Yes I wanted to access column value in OnCommand event.
     your suggestion worked quiet well.
    Thanks a lot.

    Lok..

Back to Top