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

Bind control when expanding NestedViewTemplate.

2 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jignesh
Top achievements
Rank 1
Jignesh asked on 11 Nov 2013, 08:58 PM
I have RadGrid in which I need to only bind a UserControl in Item_Created Event,when the I try to expand the NestedViewTemplate.
Right now,it is also binding the UserControl even when the I bind the RadGrid.
Is there a property to identify if the NestViewTemplate is Expand,like how when have it in GridEditFormItem,where we say e.Item.IsInEditMode.

    <telerik:RadGrid ID="radGridQuestionnaire" runat="server" 
                    Width="100%"   
                    PageSize="20"    
               AutoGenerateColumns="False" 
                    GridLines="None" 
                    AllowSorting="True" 
               AllowPaging="True" 
                    OnNeedDataSource="radGridQuestionnaire_NeedDataSource"
                    OnItemCreated="radGridQuestionnaire_ItemCreated"
                    OnItemDataBound="radGridQuestionnaire_ItemDataBound"
                    OnItemCommand="radGridQuestionnaire_ItemCommand">
        <PagerStyle Mode="NextPrevNumericAndAdvanced"/>
   <MasterTableView EnableViewState="true" DataKeyNames="Form.DisplayFormName,Question.QuestionNumber,Question.QuestionId,ReviewId" Width="100%">
            <RowIndicatorColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
   <ExpandCollapseColumn>
   <HeaderStyle Width="20px"></HeaderStyle>
   </ExpandCollapseColumn>
            <Columns>
                <telerik:GridBoundColumn HeaderText="Form" UniqueName="FormName" DataField="Form.DisplayFormName" HeaderStyle-Width="40%" />
                <telerik:GridBoundColumn HeaderText="Question #" UniqueName="QuestionNumber" DataField="Question.QuestionNumber" HeaderStyle-Width="15%" />
                <telerik:GridBoundColumn HeaderText="Status" UniqueName="QuestionnaireStatusName" DataField="QuestionnaireStatus.QuestionnaireStatusName" HeaderStyle-Width="15%" />
                <telerik:GridBoundColumn HeaderText="Submitted By" UniqueName="SubmittedBy" DataField="Questionnaire.SubmittedBy" HeaderStyle-Width="15%" />
                <telerik:GridBoundColumn HeaderText="Submitted On" UniqueName="SubmittedOn" DataField="Questionnaire.SubmittedOn" HeaderStyle-Width="15%" />
            </Columns>
            <NestedViewTemplate>
                <div id="divChoiceMain" class="pad10">
                    <div class="divChoiceTextSection">
                        <div class="divChoiceTextLeftSection">Form:</div>
                        <div class="divFloatLeft">
                            <asp:Label ID="lblFormName" runat="server" Text='<%# Eval("Form.DisplayFormName")%>'/>
                        </div>
                    </div>
                    <div class="divChoiceTextSection">
                        <div class="divChoiceTextLeftSection">Question #:</div>
                        <div class="divFloatLeft">
                            <div>
                                <asp:Label ID="lblQuestionNumber" runat="server" Text='<%#Eval("Question.QuestionNumber")%>'/>
                            </div>
                        </div>
                    </div>
                    <div class="divChoiceTextCorrectiveActionSection">
                        <div class="divFloatLeft padtop5" style="margin-left:100px;">
                            <ar:ReviewConfigurationToolTipUC ID="reviewConfigurationToolTipUC" runat="server" />
                        </div>
                    </div>
                </div>
                <div class="clearfix pad10">
                    <div class="divChoiceTextSection">
                        <div class="divFloatLeft padRight10">
                            <asp:LinkButton ID="lnkBtnSave" runat="server" Text="Save" CommandName="Save" CommandArgument='<%#Eval("Question.QuestionId")%>'></asp:LinkButton>
                        </div>
                        <div class="divFloatLeft padRight10">
                            <asp:LinkButton ID="lnkSaveAndSubmit" runat="server" Text="Save & Submit" CommandName="Submit" CommandArgument='<%#Eval("Question.QuestionId")%>'></asp:LinkButton>
                        </div>
                        <div class="divFloatLeft">
                            <asp:LinkButton ID="lnkBtnCancel" runat="server" Text="Cancel" CommandName="Cancel"></asp:LinkButton>
                        </div>
                    </div>
                </div>
            </NestedViewTemplate>
        </MasterTableView>
    </telerik:RadGrid>



protected void radGridQuestionnaire_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridNestedViewItem)
            {
                GridNestedViewItem gridNestedViewItemObj = e.Item as GridNestedViewItem;
                if (gridNestedViewItemObj == null)
                {
                    return;
}

                if (gridNestedViewItemObj.OwnerTableView.DataKeyValues != null)
                {
                    int? questionId = gridNestedViewItemObj.OwnerTableView.DataKeyValues[0]["Question.QuestionId"].ToNullableInt32();
                    if (questionId.HasValue)
                    {
                        ReviewConfigurationToolTipUC reviewConfigurationToolTipUCObj = gridNestedViewItemObj.FindControl("reviewConfigurationToolTipUC") as ReviewConfigurationToolTipUC;
                        
                        if (reviewConfigurationToolTipUCObj != null)
                        {
                            //Create FormQuestion Obj.
                            FormQuestion formQuestionObj = new FormQuestion { QuestionId = questionId };
                            reviewConfigurationToolTipUCObj.BuildToolTip(string.Empty, formQuestionObj, null);

                        }
                    }
                }
            }
        }

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 12 Nov 2013, 05:17 AM
Hello,

Please try with the below code snippet.

protected void radGridQuestionnaire_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = e.Item as GridDataItem;
 
            if (item.Expanded)
            {
                GridTableView gridTableView = item.ChildItem.NestedTableViews[0] as GridTableView;
 
                foreach (GridNestedViewItem gridNestedViewItemObj in gridTableView.GetItems(GridItemType.NestedView))
                {
                    if (gridNestedViewItemObj == null)
                    {
                        return;
                    }
 
                    if (gridNestedViewItemObj.OwnerTableView.DataKeyValues != null)
                    {
                        int? questionId = gridNestedViewItemObj.OwnerTableView.DataKeyValues[0]["Question.QuestionId"].ToNullableInt32();
                        if (questionId.HasValue)
                        {
                            ReviewConfigurationToolTipUC reviewConfigurationToolTipUCObj = gridNestedViewItemObj.FindControl("reviewConfigurationToolTipUC") as ReviewConfigurationToolTipUC;
 
                            if (reviewConfigurationToolTipUCObj != null)
                            {
                                //Create FormQuestion Obj.
                                FormQuestion formQuestionObj = new FormQuestion { QuestionId = questionId };
                                reviewConfigurationToolTipUCObj.BuildToolTip(string.Empty, formQuestionObj, null);
 
                            }
                        }
                    }
                }
            }
        }
    }
    //OR
    protected void radGridQuestionnaire_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridNestedViewItem)
        {
 
 
            GridNestedViewItem gridNestedViewItemObj = e.Item as GridNestedViewItem;
 
            GridDataItem item = gridNestedViewItemObj.ParentItem as GridDataItem;
 
            if (item.Expanded)
            {
                // parent Row is expanded
 
                if (gridNestedViewItemObj == null)
                {
                    return;
                }
 
                if (gridNestedViewItemObj.OwnerTableView.DataKeyValues != null)
                {
                    int? questionId = gridNestedViewItemObj.OwnerTableView.DataKeyValues[0]["Question.QuestionId"].ToNullableInt32();
                    if (questionId.HasValue)
                    {
                        ReviewConfigurationToolTipUC reviewConfigurationToolTipUCObj = gridNestedViewItemObj.FindControl("reviewConfigurationToolTipUC") as ReviewConfigurationToolTipUC;
 
                        if (reviewConfigurationToolTipUCObj != null)
                        {
                            //Create FormQuestion Obj.
                            FormQuestion formQuestionObj = new FormQuestion { QuestionId = questionId };
                            reviewConfigurationToolTipUCObj.BuildToolTip(string.Empty, formQuestionObj, null);
 
                        }
                    }
                }
            }
        }
    }

Let me know if any concern.

Thanks,
Jayesh Goyani
0
Jignesh
Top achievements
Rank 1
answered on 12 Nov 2013, 04:15 PM
Jayesh,

Thanks for you prompt reply.
I tried to do it in both the ways as you had mentioned in your reply.But in both the cases,the item.Expanded is always false when the Expand Button is clicked.

Is there any other way to determine it or is it a bug with the RadGrid?

Option:1
protected void radGridQuestionnaire_ItemCreated(object sender, GridItemEventArgs e)
        {
          if (e.Item is GridNestedViewItem)
            {
                GridNestedViewItem gridNestedViewItemObj = e.Item as GridNestedViewItem;
                GridDataItem parentItemObj = gridNestedViewItemObj.ParentItem as GridDataItem;
                bool isExpanded = parentItemObj.Expanded;

                if (parentItemObj.Expanded)
                {
                    if (gridNestedViewItemObj == null || parentItemObj == null)
                        return;

                    if (gridNestedViewItemObj.OwnerTableView.DataKeyValues != null)
                    {
                        int? questionId = gridNestedViewItemObj.OwnerTableView.DataKeyValues[parentItemObj.ItemIndex]["Question.QuestionId"].ToNullableInt32();

                        if (questionId.HasValue)
                        {
                            ReviewConfigurationToolTipUC reviewConfigurationToolTipUCObj = gridNestedViewItemObj.FindControl("reviewConfigurationToolTipUC") as ReviewConfigurationToolTipUC;

                            if (reviewConfigurationToolTipUCObj != null)
                            {
                                //Create FormQuestion Obj.
                                FormQuestion formQuestionObj = new FormQuestion { QuestionId = questionId };
                                reviewConfigurationToolTipUCObj.BuildToolTip(string.Empty, formQuestionObj, null, true);
                            }
                        }
                    }
                }
            }
}

Option:2

protected void radGridQuestionnaire_ItemCreated(object sender, GridItemEventArgs e)
{
if(e.Item is GridDataItem)
            {
                GridDataItem item = e.Item as GridDataItem;
 
                if(item.Expanded)
                {
                    GridTableView gridTableView = item.ChildItem.NestedTableViews[0] as GridTableView;
 
                    foreach(GridNestedViewItem gridNestedViewItemObj in gridTableView.GetItems(GridItemType.NestedView))
                    {
                        if(gridNestedViewItemObj == null)
                        {
                            return;
                        }
 
                        if(gridNestedViewItemObj.OwnerTableView.DataKeyValues != null)
                        {
                            int? questionId = gridNestedViewItemObj.OwnerTableView.DataKeyValues[0]["Question.QuestionId"].ToNullableInt32();
                            if(questionId.HasValue)
                            {
                                ReviewConfigurationToolTipUC reviewConfigurationToolTipUCObj = gridNestedViewItemObj.FindControl("reviewConfigurationToolTipUC") as ReviewConfigurationToolTipUC;
 
                                if(reviewConfigurationToolTipUCObj != null)
                                {
                                    //Create FormQuestion Obj.
                                    FormQuestion formQuestionObj = new FormQuestion { QuestionId = questionId };
                                    reviewConfigurationToolTipUCObj.BuildToolTip(string.Empty, formQuestionObj, null,true);
 
                                }
                            }
                        }
                    }
                }
            }


}
Tags
Grid
Asked by
Jignesh
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Jignesh
Top achievements
Rank 1
Share this question
or