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

[Solved] Hiding NestedViewTemplate of DetailTable

4 Answers 228 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shumaila Imran
Top achievements
Rank 1
Shumaila Imran asked on 14 Feb 2011, 04:55 PM
I've the following nested Grid structure.

<telerik:RadGrid ....>
   <MasterTableView...>
         <DetailTables>
            <GridTableView  Name="Users".....>
                  <Columns>
                          <telerik:GridBoundColumn UniqueName="Status" DataField="Status" HeaderText="Status"  AllowFiltering="false" />
                  </Columns>
                 <NestedViewTemplate>
                              ...................
                 </NestedViewTemplate>     
              </GridTableView>
           </DetailTables>
      <Columns>
           ............
      </Columns>
   </MasterTableView>
 </telerik:RadGrid>

I want to hide the NestedViewTemplate if "Status" has some specific value.

I'm binding the DetailTable as follows and probably can access the current item's Status value in the same event but not sure how to do that.

 protected void RadGridTest_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)
        {
            GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
            switch (e.DetailTableView.Name)
            {
                case "Users":
                    {
                        int testID = Convert.ToInt32(dataItem.GetDataKeyValue("ID"));
                        e.DetailTableView.DataSource = UserInTest.GetUsersInTest(testID,"Untaken");
                        break;
                    }


            }
        }

So, how can I access the current item's Column values of DetailTable and the NestedViewTemplate to hide it if the column (Status) has a certain value.

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 15 Feb 2011, 06:11 AM
Hello Shumalia,

Here is a sample code which shows how to hide the control inside NestedViewTemplate based on some condition.

ASPX:
<DetailTables>
    <telerik:GridTableView  Name="Detail2" runat="server">
        <Columns>
           <telerik:GridBoundColumn UniqueName="Status" DataField="Status" />
        </Columns>
        <NestedViewTemplate>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </NestedViewTemplate>
    </telerik:GridTableView>
</DetailTables>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridNestedViewItem && e.Item.OwnerTableView.Name == "Detail2")
        {
            GridNestedViewItem nestedItem = (GridNestedViewItem)e.Item;
            if (nestedItem.ParentItem["Status"].Text == "true")//your condition
            {
                TextBox txtbox = (TextBox)nestedItem.FindControl("TextBox1");
                txtbox.Visible = false;
            }
        }
    }

Thanks,
Princy.
0
Shumaila Imran
Top achievements
Rank 1
answered on 16 Feb 2011, 03:19 AM
Thank you, it worked.
0
Shoaib
Top achievements
Rank 1
answered on 15 Mar 2013, 05:15 AM
Hello Princy ,

Please tell me how can i do it in javascript ?????? how can I find refernece of nestedview template label or textbox and set their properties ??

Waiting for your soonly reposnse.




Regards

0
Andrey
Telerik team
answered on 19 Mar 2013, 02:55 PM
Hello,

It will be easiest to use the approach that Princy has shared and store the ID of the desired control into a hidden field. Then on the client you will use the HiddenField's value and thus you will be able to find the desired control.

All the best,
Andrey
the Telerik team
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 their blog feed now.
Tags
Grid
Asked by
Shumaila Imran
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Shumaila Imran
Top achievements
Rank 1
Shoaib
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or