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

How can i findcontrol in GridTableView

5 Answers 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ho Tri
Top achievements
Rank 1
Ho Tri asked on 16 Sep 2011, 04:26 AM
Hi all, how can i FindControl GridTableView when i click "Next" button :((. i try to find control "<asp:Label ID="OrderIDLabel" runat="server" Text='<%# Eval("OrderID") %>'></asp:Label> "
  but i can't, who can help me now
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
 
 
        <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" GridLines="None"
            ShowGroupPanel="True" Skin="Outlook" OnDetailTableDataBind="RadGrid1_DetailTableDataBind"
            HorizontalAlign="Left" DataMember="T_Company"    
                    onitemcommand="RadGrid1_ItemCommand"
                    onneeddatasource="RadGrid1_NeedDataSource"
                    onitemdatabound="RadGrid1_ItemDataBound" onprerender="RadGrid1_PreRender">
            <ClientSettings AllowDragToGroup="True">
            </ClientSettings>
            <MasterTableView Name="abc_" AutoGenerateColumns="false" AllowMultiColumnSorting="True" GridLines="Horizontal"
                DataKeyNames="CompanyID" DataMember="T_Company"
                GroupsDefaultExpanded="true">
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID" />
                </ParentTableRelation>
                <ExpandCollapseColumn Visible="True">
                </ExpandCollapseColumn>
                <Columns>
                    <telerik:GridBoundColumn DataField="CompanyName" HeaderText="Dịch Vụ" UniqueName="column2">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn DataField="Deposit" HeaderText="Đặt Cọc" UniqueName="column">
                        <EditItemTemplate>
                            <asp:Label ID="DepositLabel" runat="server" Text='<%# Eval("Deposit") %>'></asp:Label>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:TextBox ID="DepositTextBox" runat="server" Text='<%# Bind("Deposit") %>'></asp:TextBox>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn UniqueName="column1" HeaderText="Người Thanh Toán">
                        <EditItemTemplate>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource1"
                                DataTextField="GuiderName" DataValueField="GuiderID">
                            </asp:DropDownList>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
                <DetailTables>
                    <telerik:GridTableView Name="show_" runat="server" Visible="true" DataKeyNames="CompanyID"
                        DataMember="CompanyID" Width="100%" AutoGenerateColumns="false" GridLines="Horizontal"
                        ShowFooter="True" Font-Bold="False" Font-Italic="False"
                        Font-Overline="False" Font-Strikeout="False" Font-Underline="False"
                        ForeColor="Blue">
                        <ParentTableRelation>
                            <telerik:GridRelationFields DetailKeyField="CompanyID" MasterKeyField="CompanyID" />
                        </ParentTableRelation>
                        <Columns>
                            <telerik:GridTemplateColumn DataField="OrderID" HeaderText="ID" UniqueName="column1">
                                <EditItemTemplate>
                                    <asp:TextBox ID="OrderIDTextBox" runat="server" Text='<%# Bind("OrderID") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="OrderIDLabel" runat="server" Text='<%# Eval("OrderID") %>'></asp:Label>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn DataField="ProvideName" HeaderText="Dịch Vụ" UniqueName="column2">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="CurrentPrice" HeaderText="Đơn Giá" UniqueName="column3">
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn DataField="BookQty" HeaderText="SL Dự Kiến" UniqueName="column4">
                                <EditItemTemplate>
                                    <asp:TextBox ID="BookQtyTextBox" runat="server" Text='<%# Bind("BookQty") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="BookQtyLabel" runat="server" Text='<%# Eval("BookQty") %>'></asp:Label>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn DataField="PriceOper" HeaderText="TT Dự Kiến" UniqueName="column5">
                                <EditItemTemplate>
                                    <asp:TextBox ID="PriceOperTextBox" runat="server" Text='<%# Bind("PriceOper") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="PriceOperLabel" runat="server" Text='<%# Eval("PriceOper") %>'></asp:Label>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn DataField="CurrentQty" HeaderText="SL thực Tế" UniqueName="column6"
                                DataType="System.Int32">
                                <EditItemTemplate>
                                    <asp:Label ID="CurrentQtyLabel" runat="server" Text='<%# Eval("CurrentQty") %>'></asp:Label>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:TextBox ID="CurrentQtyTextBox" runat="server" Width="50" Text='<%# Eval("CurrentQty") %>'></asp:TextBox>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn DataField="CurrentPay" HeaderText="TT Thực Tế" UniqueName="column7"
                                DataType="System.Int32">
                                <EditItemTemplate>
                                    <asp:Label ID="CurrentPayLabel" runat="server" Text='<%# Eval("CurrentPay") %>'></asp:Label>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:TextBox ID="CurrentPayTextBox" runat="server" Width="50" Text='<%# Eval("CurrentPay") %>'></asp:TextBox>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn DataField="DifferenceQty" HeaderText="SL Phát Sinh" UniqueName="column9">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="DifferencePrice" HeaderText="CP Phát Sinh" UniqueName="column10">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="TotalPrice" HeaderText="Thành Tiền" UniqueName="column11">
                            </telerik:GridBoundColumn>
                        </Columns>
                        <FooterStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
                            Font-Underline="False" ForeColor="Red" Wrap="True" />
                    </telerik:GridTableView>
                </DetailTables>
            </MasterTableView>
        </telerik:RadGrid>
<asp:Button ID="Button1" runat="server" Text="Tiếp Tục"
                    onclick="Button1_Click" />

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 16 Sep 2011, 06:27 AM
Hello Mark,

You can access the label by loop through the entire row. Here is a sample code.
C#:
protected void Next_Click(object sender, EventArgs e)
    {
        foreach (GridDataItem item in rad.MasterTableView.Items)
        {
         Label lbl1=item.FindControl("Label") as Label;
 
        }
    }

Thanks,
Shinu.
0
Ho Tri
Top achievements
Rank 1
answered on 16 Sep 2011, 06:58 AM
your way i tryed but i can't, it's error "Object reference not set to an instance of an object.". You can help me fix this error i'm new in rad control :d
0
Ho Tri
Top achievements
Rank 1
answered on 16 Sep 2011, 11:53 AM
i don't konw how it return, who can help me this problemn,
0
Jayesh Goyani
Top achievements
Rank 2
answered on 16 Sep 2011, 12:14 PM
Hello,

foreach (GridDataItem item in RadGrid1.Items)
        {
            if (item.OwnerTableView.Name == "abc_")
            {
 
            }
            else if (item.OwnerTableView.Name == "show_")
            {
                Label Label1 = item.FindControl("Label") as Label;
                if (Label1 != null)
                {
                    // do your logic here
                }
            }
        }


Thanks,
Jayesh Goyani
0
Ho Tri
Top achievements
Rank 1
answered on 16 Sep 2011, 04:47 PM
Thanks Jayesh Goyani very much, this is very simple why me can't think. i'm stupid. thanks again for your help.
Tags
Grid
Asked by
Ho Tri
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Ho Tri
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or