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

SelectedItems is zero

4 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Thanh Dang
Top achievements
Rank 2
Thanh Dang asked on 02 Aug 2011, 06:24 PM
Hello

I'm getting value of a cell in selected row in RadGrid. I have enable Client-Side Row Selection and PostBackOnRowClick.

<telerik:RadGrid ID="RgdOffer" runat="server" CellSpacing="0"
     EnableEmbeddedSkins="False" GridLines="None"
      onitemcommand="RgdOffer_ItemCommand" onitemdatabound="RgdOffer_ItemDataBound"
        Skin="GPF" CssClass="shadow">
   <ClientSettings EnableRowHoverStyle="True" AllowColumnsReorder="True"
        EnablePostBackOnRowClick="True" ReorderColumnsOnClient="True">
       <Selecting AllowRowSelect="True" EnableDragToSelectRows="False" />
   </ClientSettings>


And from code-behind, I get the value of the cell with this code snippet in ItemCommand event:

if (e.CommandName == "RowClick" && e.Item is GridDataItem)
            {
                // String to store OfferNo
                string strOfferNo = null;
 
                // Get OfferNo of selected Offer
                foreach (GridDataItem item in RgdOffer.SelectedItems)
                {
                    strOfferNo = item["OfferNo"].Text;
                }

And it did work. 

But when I put my grid in to a RadDock, then SelectedItems always return 0.

I don't know why?

Can you help me explain this problem?

Thank you.

Thanh Dang

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Aug 2011, 05:53 AM
Hello Thanh,

Try the following code snippet to get the SelectedItems.
C#:
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
 if (e.CommandName == "RowClick" && e.Item is GridDataItem)
   {
       foreach (GridDataItem item in RgdOffer.MasterTableView.Items)
       {
        string strOfferNo = item["OfferNo"].Text;
       }
   }
}

Thanks,
Shinu.
0
Thanh Dang
Top achievements
Rank 2
answered on 03 Aug 2011, 06:11 AM
Thanks for your reply Shinu

But your code snippet seems to miss something... I don't see Selected elsewhere. 
This code snippet just iterate through all items in the grid. But what I need is the value at selected row only.
I have tried putting if (item.Selected)but still no luck.
Would you look at this once again.

Thanks

Thanh Dang
0
Genti
Telerik team
answered on 05 Aug 2011, 09:39 AM
Hello Thanh Dang,

Thank you for contacting us.

For more information on looping and extracting selected row keys you can get a look at the following article:
http://www.telerik.com/help/aspnet-ajax/grid-retrieve-primary-key-field-values-for-items.html



Kind regards,
Genti
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Thanh Dang
Top achievements
Rank 2
answered on 08 Aug 2011, 05:00 AM
Hello Genti

The problem here is that RadGrid1.SelectedItems always return 0 item.
I'm wondering if RadDock or RadAjaxPanel may cause some effect to RadGrid, as I put the grid under a AjaxPanel and a Dock.

Regards
Thanh Dang


Tags
Grid
Asked by
Thanh Dang
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Thanh Dang
Top achievements
Rank 2
Genti
Telerik team
Share this question
or