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

Getting data from CardView

1 Answer 27 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sparshukov
Top achievements
Rank 1
sparshukov asked on 03 Dec 2008, 08:40 AM

I’m using component RadGrid. I need to represent RadGrid like ListView for that I’m using ItemTemplate. I’m creating it (ItemTemplate) on the server-side. Because in RadGrid the columns creating dynamically. Here my code example:

SearchGridItemTemplate.cs

public enum SearchGridItemTemplateType {ReportCardTemplate, InvestigationTemplate, ReportTemplate, InvestigationObjectTemplate};

    public class SearchGridItemTemplate : ITemplate

    {

        SearchGridItemTemplateType _templateType;

        public SearchGridItemTemplate (SearchGridItemTemplateType type)

           {

            _templateType = type;

           }

        public void InstantiateIn(System.Web.UI.Control container)

        {

            Literal literal = new Literal();

            literal.DataBinding += new System.EventHandler(literal_DataBinding);

 

            container.Controls.Add(literal);

        }

        void literal_DataBinding(object sender, System.EventArgs e)

        {

             //Some code…

        }

    }

Default.aspx.cs

protected void Page_Load(object sender, EventArgs e)

      {

             //Some code…

searchResultGrid.MasterTableView.ItemTemplate = new SearchGridItemTemplate (SearchGridItemTemplateType.ReportCardTemplate);

//Some code…

}

Everything works fine, but I have some problem. The problem is in next situation. I need to get data from the selected item. I’m doing its like this:

GridDataItem[] items = searchResultGrid.MasterTableView.GetSelectedItems();

            foreach (GridDataItem item in items)

            {

                    TableCell cell = item["ID"];

//Some code…

}

But in the GridDataItem I can’t get data that I need.

How I can make it? Can you send me example or reference to that problem?

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 05 Dec 2008, 02:02 PM
Hello sparshukov,

Please review the below help topic on accessing grid cells and rows:
http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html

Additionally, you can try getting the desired value as below:

foreach (GridDataItem item in items)  
{  
   TableCell cell = item["ID"];  
   string cellValue = (item["ID"].Controls[0] as Literal).Value;  
}  
 
 

I hope this helps. 

Regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
sparshukov
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or