Find Label Control in DetailsView PagerTemplate

Discussion in 'ASP .Net Web Controls' started by clintonG, Aug 7, 2005.

  1. clintonG

    clintonG Guest

    Not as easy as the simple use of the FindControl method suggests when a
    label control is declared within the PagerTemplate of a DetailsView control.

    Anybody using Beta 2 that knows how to do this? I get close but no cigar.

    <%= Clinton Gallagher
    clintonG, Aug 7, 2005
    #1
    1. Advertising

  2. clintonG

    clintonG Guest

    Thanks for responding but still, no joy. The DetailsView control has a
    BottomPagerRow property like the GridView control but the following code
    raised the exception in comments...

    // declarations...
    <PagerTemplate>
    <asp:LinkButton ID="LinkButton1" runat="server"
    CommandArgument="First"
    CommandName="Page"
    Style="color: #232377;">&lt;&lt; First</asp:LinkButton>
    <asp:LinkButton ID="LinkButton2" runat="server"
    CommandArgument="Prev"
    CommandName="Page"
    Style="color: #232377;">&lt; Prev</asp:LinkButton>

    <asp:Label ID="PagingLabel" runat="server">
    </asp:Label>

    <asp:LinkButton ID="LinkButton3" runat="server"
    CommandArgument="Next"
    CommandName="Page"
    Style="color: #232377;">Next &gt;</asp:LinkButton>
    <asp:LinkButton ID="LinkButton4" runat="server"
    CommandArgument="Last"
    CommandName="Page"
    Style="color: #232377;">Last &gt;&gt;</asp:LinkButton>
    </PagerTemplate>

    // code-behind raises exception...
    // Object reference not set to an instance of an object.
    Label lbl = (Label)DetailsView1.BottomPagerRow.FindControl("PagingLabel");
    lbl.Text = "PagingLabel Found";

    Interesting to note that Intellisense 'sees' lbl identifying the object as
    (local variable) Label lbl and also allows the Text property to be picked.

    <%= Clinton Gallagher


    "ravikanth" <> wrote in
    message news:...
    >
    > Hi,
    > You can find the control placed in pagerTemplate.
    > You have to do following thing in your code:
    > DropDownList drp =(DropDownList)
    > GridView1.BottomPagerRow.FindControl("DropDownList1");
    >
    > Through this you can get controls placed in Pager Template.
    >
    >
    > ASP.net Control Code:
    >
    > <%@ Control Language="C#" AutoEventWireup="true"
    > CodeFile="First.ascx.cs" Inherits="First" Debug="true" %>
    > <asp:GridView ID="GridView1" runat="server"
    > DataSourceID="SqlDataSource1" AllowPaging="True"
    > AutoGenerateColumns="False" DataKeyNames="au_id">
    > <PagerTemplate >
    > <asp:DropDownList ID="DropDownList1" runat="server">
    > </asp:DropDownList>
    > </PagerTemplate>
    > <Columns>
    > <asp:BoundField DataField="au_id" HeaderText="au_id"
    > ReadOnly="True" SortExpression="au_id" />
    > <asp:BoundField DataField="au_lname" HeaderText="au_lname"
    > SortExpression="au_lname" />
    > <asp:BoundField DataField="au_fname" HeaderText="au_fname"
    > SortExpression="au_fname" />
    > <asp:BoundField DataField="address" HeaderText="address"
    > SortExpression="address" />
    > <asp:BoundField DataField="city" HeaderText="city"
    > SortExpression="city" />
    > <asp:BoundField DataField="state" HeaderText="state"
    > SortExpression="state" />
    > <asp:BoundField DataField="zip" HeaderText="zip"
    > SortExpression="zip" />
    > </Columns>
    > </asp:GridView>
    > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    > ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
    > ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName
    > %>" SelectCommand="SELECT [au_id], [au_lname], [au_fname], [address],
    > [city], [state], [zip] FROM [authors]">
    > </asp:SqlDataSource>
    >
    > ASP.net Code Behind:
    >
    > DropDownList drp =(DropDownList)
    > GridView1.BottomPagerRow.FindControl("DropDownList1");
    > for (int i = 1; i < 10; i++)
    > {
    > drp.Items.Add(new ListItem(i.ToString(),i.ToString()));
    > }
    > drp.DataBind();
    >
    >
    >
    >
    > I hope this solves your problem.
    >
    > Ravi
    >
    >
    > --
    > ravikanth
    > ------------------------------------------------------------------------
    > ravikanth's Profile: http://www.hightechtalks.com/m25
    > View this thread: http://www.hightechtalks.com/t2207265
    >
    clintonG, Aug 10, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stuart Shay

    Grid View PagerTemplate Skin

    Stuart Shay, Mar 17, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    5,193
    Stuart Shay
    Mar 17, 2006
  2. =?Utf-8?B?RGFiYmxlcg==?=

    add link to existing Gridview 2.0 default pagertemplate

    =?Utf-8?B?RGFiYmxlcg==?=, Mar 20, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    12,248
    =?Utf-8?B?RGFiYmxlcg==?=
    Mar 28, 2006
  3. Nathan Sokalski
    Replies:
    0
    Views:
    400
    Nathan Sokalski
    Jan 11, 2007
  4. Feege
    Replies:
    0
    Views:
    444
    Feege
    Dec 20, 2005
  5. Knut Krueger
    Replies:
    8
    Views:
    263
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page