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

Find GridDataItem on LinkButton click.

2 Answers 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lokesh
Top achievements
Rank 1
Lokesh asked on 24 Jul 2012, 10:52 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 24 Jul 2012, 12:44 PM
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.
0
Lokesh
Top achievements
Rank 1
answered on 24 Jul 2012, 01:07 PM
Hi Princy,
Yes I wanted to access column value in OnCommand event.
 your suggestion worked quiet well.
Thanks a lot.

Lok..
Tags
Grid
Asked by
Lokesh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Lokesh
Top achievements
Rank 1
Share this question
or