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

Bind to labels in nested radgrid

3 Answers 200 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 19 Jul 2011, 06:37 PM

I am trying to bind to my labels in my nestedview template in my radgrid, but looking at telerik site but have not been able to find how they bind throught he code behind page and get a hold of the data key in the parenttablerelation.  How can I bind to my controls via code behind page.  I thought through the detialtabledatabind but nothing works for nested views.


 Protected Sub myGridDeploy_DetailTableDataBind(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles myGridDeploy.DetailTableDataBind

        If e.DetailTableView.Name = "myUnitPos" Then
            sql = "Select intPositionId, intUnitMobId, strPosnTitle, strPara, strLine, intPositionNum, strGrade, strMOS, strASI, strAuthBr, Case when intAsgnstr = 0 " _
                & "then 'NO' else 'YES' end Filled From tblMobUnitPosition where intUnitMobID = " & e.DetailTableView.ParentItem.GetDataKeyValue("intUnitMobId") & " " _
                & "order by strPara, strLine, intPositionNum"

            e.DetailTableView.DataSource = getData(sql)
        End If

        sql = "Select intDeployId,intPositionId,si.FullName,si.strRank,si.AGE,si.strPmos,si.strSMOS,si.POSN_NBR_EXCESS_IND,si.SCTY_CLNC,si.ETS,si.strstatus,si.PHYS_PRFL_SER,si.intYearSvc, si.SRpDate,si.Deployable, " _
            & "si.email From tblMobUnitPersonnel as up LEFT JOIN vw_Soldierinfo as si on si.strssn = up.strSSN where up.intPositionId = " & e.DetailTableView.ParentItem.GetDataKeyValue("intPositionId") & ""

    End Sub


<telerik:GridTableView DataKeyNames="intPositionId" Name="myUnitPos" Width="100%" TableLayout="Fixed" BorderWidth="1px" CellPadding="6" Font-Size="10"
                                    AutoGenerateColumns="False" HeaderStyle-HorizontalAlign="Center" BorderColor="#404040" Font-Names="Veranda,arial,sans-serif" GridLines="Both" ExpandCollapseColumn-ButtonType="ImageButton"
                                    ExpandCollapseColumn-CollapseImageUrl="~/Images/30.png" ExpandCollapseColumn-ExpandImageUrl="~/Images/29.png">
                                    <ParentTableRelation>
                                        <telerik:GridRelationFields DetailKeyField="intUnitMobId" MasterKeyField="intUnitMobId" />
                                    </ParentTableRelation>
                                    <HeaderStyle Font-Bold="true" HorizontalAlign="Center" CssClass="InnerSubHeaderStyle" />
                                    <ItemStyle CssClass="InnerSubItemStyle" HorizontalAlign="Center"  />
                                    <AlternatingItemStyle CssClass="InnerSubAlernatingItemStyle" HorizontalAlign="Center" />
                                        <NestedViewSettings>
                                            <ParentTableRelation>
                                                 <telerik:GridRelationFields DetailKeyField="intPositionId" MasterKeyField="intPositionId" />
                                            </ParentTableRelation>
                                        </NestedViewSettings>
                                        <NestedViewTemplate>
                                            <asp:Panel ID="pnlInfo" runat="server" BorderStyle="Double" BorderColor="#85A3E0" Width="50%">
                                                <table >
                                                    <tr>
                                                        <td><u>Soldier Information</u></td>
                                                    </tr>
                                                    <tr>
                                                        <td style="height:5px"></td>
                                                    </tr>
                                                     <tr>
                                                        <td>
                                                            Name:&nbsp;<asp:Label ID="lblSoldier" runat="server" Text='<%#Bind("FUllName") %>'></asp:Label>&nbsp;&nbsp;
                                                            Rank:&nbsp;<asp:label ID="lblRank" runat="server" Text='<%#Bind("strRank") %>'></asp:label>&nbsp;&nbsp;
                                                            Age:&nbsp;<asp:Label ID="lblAge" runat="server" Text='<%#Bind("AGE") %>'></asp:Label>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="height:5px"></td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            PMOS:&nbsp;<asp:Label ID="lblPMOS" runat="server"></asp:Label>&nbsp;&nbsp;
                                                            SMOS:&nbsp;<asp:label ID="lblSMOS" runat="server"></asp:label>&nbsp;&nbsp;
                                                            POSN Excess:&nbsp;<asp:Label ID="lblPOSN" runat="server"></asp:Label>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="height:5px"></td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Clearance:&nbsp;<asp:Label ID="lblClear" runat="server"></asp:Label>&nbsp;&nbsp;
                                                            ETS\MRD:&nbsp;<asp:label ID="lblEts" runat="server"></asp:label>&nbsp;&nbsp;
                                                            Full-Time:&nbsp;<asp:Label ID="lblFullTime" runat="server"></asp:Label>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="height:5px"></td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            PULHES:&nbsp;<asp:Label ID="lblPuhles" runat="server"></asp:Label>&nbsp;&nbsp;
                                                            Yrs Active:&nbsp;<asp:label ID="lblYrsActive" runat="server"></asp:label>
                                                        </td>
                                                    </tr>
                                                     <tr>
                                                        <td style="height:5px"></td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            SRP Date:&nbsp;<asp:Label ID="lblDtSrp" runat="server"></asp:Label>&nbsp;&nbsp;
                                                            Deployable:&nbsp;<asp:label ID="lblDeplyable" runat="server"></asp:label>
                                                        </td>
                                                    </tr>
                                                     <tr>
                                                        <td style="height:5px"></td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Email:&nbsp;<asp:Label ID="lblEmail" runat="server"></asp:Label>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </asp:Panel>
                                        </NestedViewTemplate>
                                        <Columns>




3 Answers, 1 is accepted

Sort by
0
Genti
Telerik team
answered on 22 Jul 2011, 04:56 PM
Hi Kevin,

In this case you can make use of the ItemDataBound event and check whether the item currently bound is of type GridNestedViewItem. If so, find the control inside it and update it accordingly.
Here's some sample code:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridNestedViewItem)
    {
        GridNestedViewItem item = (GridNestedViewItem)e.Item;
                        //populate the controls with data, in this case Im populating some text with the id of the parent row
        (item.FindControl("idLabel") as Label).Text = ((System.Data.DataRowView)(e.Item.DataItem)).Row["OrderID"].ToString();
    }
}

I am also attaching a simple solution using the Northwind database.

Greetings,
Genti
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Kevin
Top achievements
Rank 1
answered on 22 Jul 2011, 07:59 PM
Hi I created my Itemdatabound event but when i type in the first statement of
  If (e.Item Is GridNestedViewItem) Then

If get a blue underline under  GridNestedViewItem

Do you have the Vb.net equivalant of your code
Thank
0
Genti
Telerik team
answered on 25 Jul 2011, 08:49 AM
Hi Kevin,

Thank you for contacting us back.

In order to convert your code from C# to VB you can make use of the following online converter provided by Telerik:
Telerik Code Converter

Hope this helps.

Best wishes,
Genti
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Genti
Telerik team
Kevin
Top achievements
Rank 1
Share this question
or