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

Create data and controls dynamically in FormTemplate or NestedViewTemplate

2 Answers 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jignesh
Top achievements
Rank 1
Jignesh asked on 25 Oct 2013, 12:55 AM
I am binding the RadGrid with the List of  QuestionManager Object as shown below: 

public class QuestionManager
{
        public FormType FormType { get; set; }
        public Form Form { get; set; }
        public Question Question { get; set; }
}

Question object futher has a property of List<Choice>.

public class Question
{
public int QuestionId{get;set;}
public string QuestionNumber{get;set;}
public List<Choice> ChoiceList{get;set;}}



I am using a stored procedure that gets all the data and so no round trip is required.

The grid shows the FormType,FormName and Question # column.

When the edit button on each question is clicked,I need to populate all data and control available in List<Choice> Object of the respective question.

To achieve this what should I use FormTemplate or NestedViewTemplate?

Is there a way where I can iterate the List<Choice> in markup in a loop?

How should I get the List<Choice> for each question?I dont want to hit the DB again as it will be expensive.

Is there any place in grid to store the List<Choice> collection so that I need not have to hit the DB?

Any help will be appreciated !!!!.

2 Answers, 1 is accepted

Sort by
0
Jignesh
Top achievements
Rank 1
answered on 28 Oct 2013, 12:43 AM
I added the data rquired in DataKeyNames of MasterTableView of the RadGrid. And in the ItemDataBound function,I m retrieving it.

<MasterTableView EnableViewState="true"  DataKeyNames="FormType.FormTypeCode,Form.FormId,Question.QuestionId,Question.ChoiceList">

string formTypeCode = radGrid.MasterTableView.DataKeyValues[e.Item.ItemIndex]["FormType.FormTypeCode"].ToString();
string formId = radGrid.MasterTableView.DataKeyValues[e.Item.ItemIndex]["Form.FormId"].ToString();
string questionId = radGrid.MasterTableView.DataKeyValues[e.Item.ItemIndex]["Question.QuestionId"].ToString();
Object objectChoiceList = radGrid.MasterTableView.DataKeyValues[e.Item.ItemIndex]["Question.ChoiceList"];

List<Choice> choiceList = null;

if (objectChoiceList != null)

choiceList = objectChoiceList as List<Choice>;

if (choiceList != null && choiceList.Count > 0)
{
//TODO:    
}
0
Angel Petrov
Telerik team
answered on 29 Oct 2013, 03:18 PM
Hello Jignesh,

Indeed the OnItemDataBound event should be used in order to obtain the a reference to the list of Choice objects. For example if you are using the default EditForms EditMode you can obtain a reference to the values when an item is opened for edit by executing the below shown logic:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        GridEditableItem editItem = e.Item as GridEditableItem;
        if (editItem != null && editItem.IsInEditMode)
        {
            List<Choice> currnetList = (editItem.DataItem as QuestionManager).Question.ChoiceList;
        }
    }
 

Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Jignesh
Top achievements
Rank 1
Answers by
Jignesh
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or