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

ow do I get the value of a column in if it is nestedviewtemplate

8 Answers 190 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DragonBall
Top achievements
Rank 1
DragonBall asked on 30 Jul 2008, 08:17 AM
I have a grid and i have another grid nested on it (im using nestedviewtemplate)
how do I get the value of a column in if it is nested?

how do i call it in c#?

Radgrid1 -topmost
mastertableview
  Nestedviewtemplate   
   Radgrid2 --> meeting_notes_txt(column)
    mastertableview

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MeetingDetails.ascx.cs" Inherits="Components_Controls_MeetingDetails" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

<style type="text/css">
.notVisible{display:none;}
</style>
<asp:SqlDataSource ID="SqlDSProjectMeetings" runat="server"
    ConnectionString="<%$ ConnectionStrings:MeetWebStyleConnectionString %>"
    SelectCommand="MWS_Meetings_GetByProject_id"
    SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:QueryStringParameter DefaultValue="2" Name="Project_id"
            QueryStringField="project_id" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDSMeetingNotes" runat="server"
    ConnectionString="<%$ ConnectionStrings:MeetWebStyleConnectionString %>"
    SelectCommand="MWS_Meeting_notes_GetByMeeting_id"
    SelectCommandType="StoredProcedure"
    onselecting="SqlDSMeetingNotes_Selecting">
    <SelectParameters>
        <asp:ControlParameter ControlID="RadGrid1" Name="Meeting_id"
            PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>

<telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
</telerik:RadScriptManager>

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>

<asp:SqlDataSource ID="SqlDSMeetingAgenda" runat="server"
    ConnectionString="<%$ ConnectionStrings:MeetWebStyleConnectionString %>"
    SelectCommand="MWS_Meeting_agenda_GetByMeeting_id"
    SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:ControlParameter ControlID="RadGrid1" DefaultValue="" Name="Meetings_id"
            PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
</telerik:RadScriptBlock>
<telerik:RadGrid ID="RadGrid1" runat="server"
    DataSourceID="SqlDSProjectMeetings" GridLines="None"
    onneeddatasource="RadGrid1_NeedDataSource">
<MasterTableView datasourceid="SqlDSProjectMeetings" datakeynames="meetings_id"
        HorizontalAlign="NotSet" AllowPaging="True">
 
   
   
<NestedViewTemplate>

<fieldset style="padding:10px; azimuth:far-left; size:landscape; width:90%;">
    <legend style="padding:5px;"><b>Sub Menu</b>  

    <fieldset style="padding:10px; size:portrait; width:30%;">
        <legend style="padding:5px;"><b>Meetings Notes</b>
            <asp:Label ID="Label1" Font-Bold="true" Font-Italic="true" Text='<%# Eval("meetings_id") %>' Visible="false" runat="server" />
        </legend>
   
   <asp:SqlDataSource ID="SqlDSMeetingNotes" runat="server"
        ConnectionString="<%$ ConnectionStrings:MeetWebStyleConnectionString %>"
        SelectCommand="MWS_Meeting_notes_GetByMeeting_id"
        SelectCommandType="StoredProcedure"
        onselecting="SqlDSMeetingNotes_Selecting">
     
        <SelectParameters>
           
            <asp:ControlParameter ControlID="Label1" PropertyName="Text" Type="String" Name="meeting_id" />
           
        </SelectParameters>
       

    </asp:SqlDataSource>
                              
 
    <telerik:RadGrid ID="RAD1" DataSourceID="SqlDSMeetingNotes"   HeaderStyle-CssClass="notVisible"
     AutoGenerateColumns="false" runat="server">
    <MasterTableView>
    <GroupHeaderItemStyle CssClass="notVisible" />
    <HeaderStyle CssClass="notVisible " />
    <Columns>
        <telerik:GridBoundColumn DataField="meeting_note_text"  UniqueName="Discussion"
         FooterText="Discussion">
         </telerik:GridBoundColumn>
    </Columns>
   
   
    </MasterTableView>
     </telerik:RadGrid>
   
   
    </fieldset>
</NestedViewTemplate>
   
    <RowIndicatorColumn Visible="False"><HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn><ExpandCollapseColumn Resizable="False"><HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
    <Columns>
        <telerik:GridTemplateColumn UniqueName="TemplateColumn">
            <HeaderStyle Width="2cm" />
        </telerik:GridTemplateColumn>
    </Columns>
    <EditFormSettings><PopUpSettings ScrollBars="None"></PopUpSettings>
</EditFormSettings>
</MasterTableView></telerik:RadGrid>

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Jul 2008, 11:00 AM
Hello Manuel,

Try out the following code snippet to get the required result.
cs:
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.Items) 
        { 
            if (item.Expanded) 
            { 
                foreach (GridNestedViewItem nestedViewItem in RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)) 
                { 
                    RadGrid Grid2 = (RadGrid)nestedViewItem.FindControl("RAD1"); 
                    foreach (GridDataItem childItem in Grid2.MasterTableView.Items) 
                    { 
                        string strTxt = childItem["Discussion"].Text.ToString(); 
                        
                    } 
                } 
            } 
        } 
    } 

Thanks
Princy.
0
DragonBall
Top achievements
Rank 1
answered on 01 Aug 2008, 09:09 AM
Thanx for the advice and it work but how do i use it in itemcommand event since it will read all the data, i only want the data that is being selected in the itemcommand event. can you help me please.
0
DragonBall
Top achievements
Rank 1
answered on 01 Aug 2008, 09:19 AM
it works but i only want to get a single item not all the item since it is using foreach.

how to i get the item when i select it on the grid ?
0
Princy
Top achievements
Rank 2
answered on 01 Aug 2008, 09:41 AM
Hi Manuel,

You can access the selected item in a child table as shown below.

CS:
 foreach (GridNestedViewItem item1 in RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)) 
        { 
            RadGrid Grid2 = (RadGrid)item1.FindControl("RadGrid2"); 
 
 
            foreach (GridDataItem childitem in Grid2.MasterTableView.Items) 
                { 
                    if (childitem.Selected) 
                    { 
                        string strtxt = childitem["columnUniqueName"].Text; 
                    } 
                } 
             
        } 


Princy.
0
DragonBall
Top achievements
Rank 1
answered on 01 Aug 2008, 01:22 PM
it works princy thanx again. but when i try to expand the item without selecting it it wont pass this code:

i need to get the value whenever the childitem is expanded. what is wrong with my code?


if (childitem.Expanded)
                {

                    string strtxt = childitem["thumbnail_available"].Text;
  }
0
Princy
Top achievements
Rank 2
answered on 04 Aug 2008, 10:31 AM
Hello Manuel,

The code given below should solve your query, provided you set the EnablePostBackOnRowClick property as shown.
aspx:
<MasterTableView DataSourceID="SqlDataSource1" >               
             <NestedViewTemplate> 
                <telerik:RadGrid ID="RadGrid2" AutoGenerateColumns="false" AllowPaging="true" PageSize="5" DataSourceID="SqlDataSource1" runat="server"
                   <MasterTableView DataSourceID="SqlDataSource1">                     
                     <Columns> 
                     <telerik:GridBoundColumn DataField="SupplierID" UniqueName="SupplierID"></telerik:GridBoundColumn>                     
                     </Columns> 
                   </MasterTableView> 
                     <ClientSettings EnablePostBackOnRowClick="true"
                         <Selecting AllowRowSelect="true" />                          
                     </ClientSettings>                     
                </telerik:RadGrid> 
             </NestedViewTemplate> 
          <Columns>    
                <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName" UniqueName="ProductName"
                </telerik:GridBoundColumn>                  
          </Columns> 
</MasterTableView> 

cs:
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.Items) 
        { 
            if (item.Expanded) 
            { 
                foreach (GridNestedViewItem item1 in RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)) 
                { 
                    RadGrid Grid2 = (RadGrid)item1.FindControl("RadGrid2"); 
                    foreach (GridDataItem childitem in Grid2.MasterTableView.Items) 
                    { 
                        if (childitem.Selected) 
                        { 
                            string strtxt = childitem["SupplierID"].Text; 
                        } 
                    } 
                } 
            } 
        } 

Thanks
Princy
0
DragonBall
Top achievements
Rank 1
answered on 05 Aug 2008, 09:05 AM

Hi Princyi appreciate your help but i have another problem , i need to store the dataset to detailsview but it won work it returns a value after searching and storing to a new detailsview

 foreach (GridNestedViewItem item1 in RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)) 


  RadGrid Grid2 = (RadGrid)item1.FindControl("RadGrid2"); 

DetailsView dv=(DetailsView)Grid2.FindControl("DetailsView1"); //it returns a null value

dv.datasource=ds;

}
0
Accepted
Princy
Top achievements
Rank 2
answered on 05 Aug 2008, 11:01 AM
Hello Manuel,

You need to loop through the NestedViewItems of RadGrid2 and then access the DetailsView. Try out the code given below.
cs:
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    {                    
         foreach (GridNestedViewItem item1 in RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)) 
                { 
                    RadGrid Grid2 = (RadGrid)item1.FindControl("RadGrid2"); 
                    DetailsView dv = (DetailsView)Grid2.FindControl("DetailsView1"); 
                    foreach (GridNestedViewItem item2 in Grid2.MasterTableView.GetItems(GridItemType.NestedView)) 
                    { 
                        DetailsView dv = (DetailsView)item2.FindControl("DetailsView1"); 
                        dv.DataSource = ds;
                    } 
                } 
   } 

Thanks
Princy.

Tags
Grid
Asked by
DragonBall
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
DragonBall
Top achievements
Rank 1
Share this question
or