Find Label Control in DetailsView PagerTemplate

C

clintonG

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
 
C

clintonG

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 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top