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

how to find control inside RadPageView

6 Answers 504 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Babu Puchakayala
Top achievements
Rank 1
Babu Puchakayala asked on 16 Jul 2010, 04:29 PM
Dear Telerik Team,

I have a radgrid with editformtemplate in it. Inside Editform template i have a radtab with set a textboxes and gridview.  I just want to access those text boxes and gridview inside that radtabs. When I am trying to access those using findcontrol I am getting null values. Any ides how to get the values of textboxes and gridviews. here is my code..


<telerik:RadGrid ID="rg200" runat="server" AutoGenerateColumns="False" PageSize="20"
                        Height="550px" Width="100%" AllowPaging="True" AllowSorting="True" AllowMultiRowSelection="True"
                        EnableHeaderContextMenu="True" GridLines="None" AllowMultiRowEdit="true" AllowFilteringByColumn="True"
                        OnNeedDataSource="rg200_NeedDataSource" OnItemCommand="rg200_ItemCommand" OnItemCreated="rg200_ItemCreated">
                        <MasterTableView GridLines="None" DataKeyNames="orderId" CommandItemDisplay="Top"
                            EditMode="EditForms">
                            <Columns>
                                <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" HeaderStyle-Width="3%"
                                    ItemStyle-Width="3%">
                                    <HeaderStyle Width="3%"></HeaderStyle>
                                    <ItemStyle Width="3%"></ItemStyle>
                                </telerik:GridClientSelectColumn>
                                <telerik:GridBoundColumn UniqueName="sId" HeaderText="sId" DataField="sId" ReadOnly="true"
                                    Visible="false">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="orderId" HeaderText="orderId" Visible="false"
                                    ReadOnly="true" DataField="orderId">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="Project Name" HeaderText="Project Name" DataField="Project Name"
                                    ReadOnly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn UniqueName="Site Name" HeaderText="Site Name" DataField="SiteName"
                                    ReadOnly="true">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lnkSiteName" runat="server" Text='<%# Eval( "Site Name" ) %>'
                                            ForeColor="Blue" CommandName="sitename"></asp:LinkButton>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn UniqueName="Task Status" HeaderText="Task Status" DataField="Task Status"
                                    ReadOnly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="Clarify Account Nbr" HeaderText="Clarify Account Nbr"
                                    DataField="Clarify Account Nbr">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="Site ID" HeaderText="Site ID" DataField="Site ID">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="Quote ID" HeaderText="Quote ID" DataField="Quote ID">
                                </telerik:GridBoundColumn>
                                <telerik:GridCheckBoxColumn UniqueName="EDP Created?" HeaderText="EDP Created?" DataField="EDP Created?">
                                </telerik:GridCheckBoxColumn>
                                <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" Display="false">
                                </telerik:GridEditCommandColumn>
                            </Columns>
                            <EditFormSettings EditFormType="Template">
                                <FormTemplate>
                                    <table id="Table1" cellspacing="1" cellpadding="1">
                                        <tr>
                                            <td>
                                                <telerik:RadTabStrip runat="server" ID="RadTabStrip1" Orientation="HorizontalTop"
                                                    SelectedIndex="0" MultiPageID="RadMultiPage1">
                                                    <Tabs>
                                                        <telerik:RadTab Text="Task Data" PageViewID="RadPageView1">
                                                        </telerik:RadTab>
                                                        <telerik:RadTab Text="Notes" PageViewID="RadPageView2">
                                                        </telerik:RadTab>
                                                    </Tabs>
                                                </telerik:RadTabStrip>
                                                <telerik:RadMultiPage runat="server" ID="RadMultiPage1" SelectedIndex="0">
                                                    <telerik:RadPageView runat="server" ID="RadPageView1">
                                                        <..... some code here .....>
                                                    </telerik:RadPageView>
                                                    <telerik:RadPageView runat="server" ID="RadPageView2">
                                                        <table id="Table2" cellspacing="1" cellpadding="1" width="250" border="0">
                                                            <tr>
                                                                <td>
                                                                    <legend><b>Add Notes</b></legend>
                                                                    <table id="Tablenotes">
                                                                        <tr>
                                                                            <td align="left">
                                                                                Note Type :
                                                                                <asp:DropDownList ID="ddlNoteType" runat="server">
                                                                                </asp:DropDownList>
                                                                            </td>
                                                                            <td align="left">
                                                                            </td>
                                                                        </tr>
                                                                        <tr>
                                                                            <td align="left" colspan="2">
                                                                                Note Description
                                                                            </td>
                                                                        </tr>
                                                                        <tr>
                                                                            <td align="left">
                                                                                <asp:TextBox ID="txtNoteDesc" runat="server" TextMode="MultiLine" Rows="2" Width="650px"></asp:TextBox>
                                                                            </td>
                                                                            <td>
                                                                                   
                                                                                <asp:ImageButton ID="btnAddNote" CommandName='AddNote' runat="server" ToolTip="Add Note"
                                                                                    ImageUrl="~/Images/add-icon.png" />
                                                                                <asp:ImageButton Visible="false" ToolTip="Update" OnClick="imgbtnNotesUpdate_Click"
                                                                                    ID="imgbtnNotesUpdate" runat="server" ImageUrl="~/Images/accept-icon.png" />
                                                                                <asp:ImageButton Visible="false" ToolTip="Cancel" OnClick="imgbtnNotesCancel_Click"
                                                                                    ID="imgbtnNotesCancel" runat="server" ImageUrl="~/Images/delete-icon.png" />
                                                                            </td>
                                                                        </tr>
                                                                        <tr>
                                                                            <td>
                                                                            </td>
                                                                        </tr>
                                                                    </table>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    <div style="overflow: auto; height: 160px">
                                                                        <asp:GridView ID="gvNotes" BorderColor="#004000" runat="server" AutoGenerateColumns="false"
                                                                            BackColor="White" BorderWidth="1px" BorderStyle="Solid" CellSpacing="0" Width="100%"
                                                                            OnSelectedIndexChanged="gvNotes_SelectedIndexChanged" OnRowDataBound="gvNotes_RowDataBound">
                                                                            <HeaderStyle Height="20px" BackColor="#004000" Font-Size="8pt" Font-Bold="True" ForeColor="White"
                                                                                HorizontalAlign="Center" BorderColor="White" BorderWidth="0px" />
                                                                            <PagerSettings Mode="NumericFirstLast"></PagerSettings>
                                                                            <RowStyle ForeColor="#000000" Font-Size="8pt" HorizontalAlign="Left" BorderWidth="1px"
                                                                                BorderColor="#004000" />
                                                                            <AlternatingRowStyle Font-Size="8pt" ForeColor="#000000" BackColor="#F5F5E9" BorderWidth="1px"
                                                                                BorderColor="#004000" />
                                                                            <PagerStyle HorizontalAlign="Right" Font-Bold="true" Font-Size="8pt" />
                                                                            <Columns>
                                                                                <asp:TemplateField Visible="false">
                                                                                    <ItemTemplate>
                                                                                        <asp:Label ID="lblonID" runat="server" Text='<%# Bind("onID") %>'></asp:Label>
                                                                                    </ItemTemplate>
                                                                                    <ItemStyle HorizontalAlign="Left" />
                                                                                </asp:TemplateField>
                                                                                <asp:BoundField HeaderText="Note Description" DataField="Description" />
                                                                                <asp:BoundField HeaderText="Note Type" DataField="Type" />
                                                                                <asp:BoundField HeaderText="Created By" DataField="CreatedBy" />
                                                                                <asp:BoundField DataFormatString="{0:MM/dd/yyyy}" HeaderText="Created Date" DataField="CreationDate" />
                                                                            </Columns>
                                                                        </asp:GridView>
                                                                    </div>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </telerik:RadPageView>
                                                </telerik:RadMultiPage>
                                            </td>
                                        </tr>
                                    </table>
                                </FormTemplate>
                            </EditFormSettings>
                        </MasterTableView>
                        <ClientSettings AllowColumnsReorder="True">
                            <Scrolling AllowScroll="true" UseStaticHeaders="true" />
                            <Selecting AllowRowSelect="true" />
                            <Resizing AllowColumnResize="true" />
                            <ClientEvents OnRowContextMenu="RowContextMenu" OnRowSelected="OnRowSelected" OnRowDeselecting="OnRowDeselecting" />
                        </ClientSettings>
                        <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true"></PagerStyle>
                    </telerik:RadGrid>


here is my cs code


if (e.CommandName == "AddNote")
        {
            clsTaskUpdates_BL objBL = new clsTaskUpdates_BL();
            string strName = Session["UserName"].ToString();
            GridEditableItem editedItem = e.Item as GridEditableItem;
            GridEditFormItem item = e.Item as GridEditFormItem;
            GridDataItem dataitem = e.Item as GridDataItem;
 
            TextBox Notedesc = editedItem.FindControl("txtNoteDesc") as TextBox;
            GridView gvNotes = (editedItem.FindControl("gvNotes") as GridView);
            string OrdID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["orderId"].ToString();
            TextBox Notedescd = (TextBox)dataitem.NamingContainer.FindControl("txtNoteDesc") as TextBox;
            string NoteDesc = (editedItem.NamingContainer.FindControl("txtNoteDesc") as TextBox).Text;
            string NoteType = (editedItem.FindControl("ddlNoteType") as DropDownList).Text;
            
        }



I tried in all directions that i showed in my C# code. But no luck can any one help me how to get the values. I am always getting null values for txtNoteDesc, ddlNoteType and gvNotes..

Thanks

Babu

6 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 21 Jul 2010, 12:42 PM
Hello Babu,

Could you please try getting the txtNoteDesc, ddlNoteType and gvNotes controls with the following code snippet and let me know if the issue still persists:
if (e.CommandName == "AddNote")
{
      clsTaskUpdates_BL objBL = new clsTaskUpdates_BL();
      string strName = Session["UserName"].ToString();
      GridEditableItem editedItem = e.Item as GridEditableItem;
      GridEditFormItem item = e.Item as GridEditFormItem;
      GridDataItem dataitem = e.Item as GridDataItem;
 
      TextBox Notedesc = editedItem.FindControl("RadPageView2").FindControl("txtNoteDesc") as TextBox;
      GridView gvNotes = (editedItem.FindControl("RadPageView2").FindControl("gvNotes") as GridView);
      string OrdID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["orderId"].ToString();
      TextBox Notedescd = (TextBox)dataitem.NamingContainer.FindControl("txtNoteDesc") as TextBox;
      string NoteDesc = (editedItem.NamingContainer.FindControl("txtNoteDesc") as TextBox).Text;
      string NoteType = (editedItem.FindControl("RadPageView2").FindControl("ddlNoteType") as DropDownList).Text;
 }

I hope this helps.

Kind regards,
Radoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Babu Puchakayala
Top achievements
Rank 1
answered on 26 Jul 2010, 01:30 AM
Hi Radosla,

Sorry for my delay. I tried your way I am getting following error. see image.

this is what i wrote

string Notedescd = (editedItem.FindControl("RadPageView2").FindControl("txtNoteDesc") as TextBox).Text;

I also tried this way....


TextBox Notedescd = editedItem.FindControl("RadPageView2").FindControl("txtNoteDesc") as TextBox;

0
Radoslav
Telerik team
answered on 28 Jul 2010, 02:19 PM
Hi Babu,

I am sending you a simple example, based on your code. Please check it out and let me know what differs in your case.
Looking forward for your reply.

Kind regards,
Radoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Bünyamin
Top achievements
Rank 1
answered on 16 May 2012, 11:20 AM
Hi Radoslav,

Its a bit old post but I am in a situation so close to this one and  I am a bit new to this.

My problem is I used your example and I can reach the textboxes as you sayed while adding new record but when I try it on "Edit" command it returns null value.

What I want to do is getting the ID that is in a text box that is in a rad page view that is in a grid edit form template.

I hope that i can explained my situation.


Thanks
0
Shinu
Top achievements
Rank 2
answered on 16 May 2012, 11:56 AM
Hello Bunyamin,

You cannot access the control inside editform in EditCommand event. Try accessing the control in ItemDataBound event as shown below.
C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
  if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
  {
      GridEditFormItem item = (GridEditFormItem)e.Item;
      RadMultiPage page = (RadMultiPage)item.FindControl("RadMultiPage1");
      TextBox txt = item.FindControl("RadPageView1").FindControl("TextBox1") as TextBox;
   }
}

Thanks,
Shinu.
0
Bünyamin
Top achievements
Rank 1
answered on 16 May 2012, 12:24 PM
Hi Shinu,

Thank you for your quick reply. It worked realy nice.

Thank you so much..
Tags
Grid
Asked by
Babu Puchakayala
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Babu Puchakayala
Top achievements
Rank 1
Bünyamin
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or