Find Control Of text box in header of radgrid

6 posts, 0 answers
  1. Shubham
    Shubham avatar
    3 posts
    Member since:
    May 2009

    Posted 23 May 2009 Link to this post

    Hi All,

    I am using telerik Rad Grid in my applilcation.I have placed a text box in the header of one column of this rad grid.

    I am able to find the control of header and text box but my problem is that I am not able to get the text typed in that text box.
    Here I am typing the code how I am finding the control of header and text box.

    Dim header as Gridheaderitem=TryCast(RadGrid1.mastertableview.GetItemTypes(Getitem.header)(0),Gridheaderitem)
    Dim textbox as textbox=Ctype(header.findControl("textbox"),textbox)
    Dim strtext as string=textbox.text

    Please see this if anyone is able to solve this problem...thanx in advance.

    shubham
  2. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 24 May 2009 Link to this post

    Hello shubham-

    Sorry to hear you're having trouble with this scenario. The most common problem in cases like this is "timing." That is, trying to access the value of a control at the wrong time in the page lifecycle. 

    Can you please provide a small code snippet (using the "Fromat Code Block" forum tool - next to the spell check) showing where you use the code you supplied (i.e. what event this code is contained in)? That will help with debugging.

    Also, can you elaborate on your scenario? If I better understand what it is you're trying to do, I may be able to point you at existing resources that will more quickly help you solve the problem.

    Hope to help more-
    Todd
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shubham
    Shubham avatar
    3 posts
    Member since:
    May 2009

    Posted 24 May 2009 Link to this post

    Hi Todd,

    I am using this code in the button- click event.This link- button is also placed in header with the textbox.and I using onclick property
    of this link button.
    Actually I want to show the text typed in the header in one of the column of my radgrid that's why I want to retrieve the
    value of text typed in the textbox placed in the header of radgrid.


    Thanks
    Shubham
  5. Shubham
    Shubham avatar
    3 posts
    Member since:
    May 2009

    Posted 24 May 2009 Link to this post

    Hi Todd,

    Here is my code......

    In ascx  page

    <telerik:RadGrid ID="rgVerbatim" DataSourceID="ObjVerbatimswithCodes" runat="server"
                            AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" GridLines="None"
                            Skin="Office2007" Width="1320px" Height="700px" Style="margin-right: 0px" PageSize="30">
                            <HeaderContextMenu>
                                <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
                            </HeaderContextMenu>
                            <PagerStyle NextPageText="Next" PrevPageText="Previous" Mode="NextPrevNumericAndAdvanced" />
                            <MasterTableView DataSourceID="ObjVerbatimswithCodes" Width="100%" AutoGenerateColumns="False">
                                <RowIndicatorColumn>
                                    <HeaderStyle Width="20px"></HeaderStyle>
                                </RowIndicatorColumn>
                                <ExpandCollapseColumn>
                                    <HeaderStyle Width="20px"></HeaderStyle>
                                </ExpandCollapseColumn>
                                <Columns>
                                    <telerik:GridTemplateColumn UniqueName="TemplateColumn" AllowFiltering="False">
                                        <HeaderTemplate>
                                            <asp:TextBox ID="txtCodeNumber" runat="server" Width="39px" />
                                            <asp:LinkButton ID="lnkAddCode" runat="server" Text="Add Bulk Code" OnClick="lnkAddCode_Click" />/
                                            <asp:LinkButton ID="lnkRemoveCode" runat="server" Text="Remove Bulk Code" />
                                        </HeaderTemplate>

                                        <ItemTemplate>
                                            <asp:HiddenField ID="hdnCodes" runat="server" Value='<%#Eval("Codes")%>' />
                                            <asp:DataList ID="dlTextboxes" runat="server" DataSourceID="ObjMaxCodeCountDs" OnPreRender="dlTextboxes__prerender">
                                                <ItemTemplate>
                                                    <asp:TextBox ID="txtCodes" runat="server" Width="35px" />
                                                </ItemTemplate>
                                            </asp:DataList>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridBoundColumn DataField="Verbatim" HeaderText="Verbatim" UniqueName="Verbatim">
                                        <HeaderStyle Width="900px" />
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Frequency" HeaderText="Frequency" UniqueName="Frequency">
                                        <HeaderStyle Width="120px" />
                                    </telerik:GridBoundColumn>
                                </Columns>
                            </MasterTableView>
                            <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
                                Font-Underline="False" Wrap="True" />
                            <ClientSettings>
                                <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                            </ClientSettings>
                            <FilterMenu>
                                <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
                            </FilterMenu>
                        </telerik:RadGrid>

    In ascx.vb page--

      Protected Sub lnkAddCode_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        
            Dim header As GridHeaderItem = TryCast(rgVerbatim.MasterTableView.GetItems(GridItemType.Header)(0), GridHeaderItem)
            Dim txtCodeNumber As TextBox = CType(header.FindControl("txtCodeNumber"), TextBox)
            Dim str as string= txtCodeNumber.text
        End Sub

    Plese check if now you can help me.

    Thanks
  6. jon
    jon avatar
    33 posts
    Member since:
    Dec 2008

    Posted 22 Sep 2010 Link to this post

    I have this same issue with the same code scenario.  Was there a solution to this issue of getting the value from the textboxes in the header?

    Thanks.
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Sep 2010 Link to this post

     Hello Jon,

     I tried a code snimilar to this for a similar scenario and that worked fine for me.

    Vb.Net:
    Protected Sub lnkAddCode_Click(sender As Object, e As EventArgs)
        Dim header As GridHeaderItem = TryCast(RadGrid1.MasterTableView.GetItems(GridItemType.Header)(0), GridHeaderItem)
        Dim txtCodeNumber As TextBox = DirectCast(header.FindControl("txtCodeNumber"), TextBox)
        Dim str As String = txtCodeNumber.Text
    End Sub

    And the ASPX is:
    <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AutoGenerateColumns="false"
        DataSourceID="SqlDataSource1" AutoGenerateEditColumn="true" >
        <MasterTableView Width="100%" DataKeyNames="EmployeeID" CommandItemDisplay="Top"
            EditMode="PopUp">
            <Columns>
               <telerik:GridTemplateColumn>
                    <HeaderTemplate>
                        <asp:TextBox ID="txtCodeNumber" runat="server" Width="39px" />
                       <asp:LinkButton ID="lnkAddCode" runat="server" Text="Add Bulk Code" OnClick="lnkAddCode_Click" />
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%#Bind("FirstName") %>' Width="39px" />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    Give a try with this code and see whether it helps.

    Vb.Net:
    Protected Sub lnkAddCode_Click(sender As Object, e As EventArgs)
        Dim btn As LinkButton = DirectCast(sender, LinkButton)
        Dim header As GridHeaderItem = DirectCast(btn.NamingContainer, GridHeaderItem)
        ' access HeaderItem
        Dim txtCodeNumber As TextBox = DirectCast(header.FindControl("txtCodeNumber"), TextBox)
        Dim str As String = txtCodeNumber.Text
    End Sub


    Thanks,
    Princy.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017