Retrieving a literal value from a datagrid footer

N

nathan.cutmore

BACKGROUND:
I have a bound datagrid with the following code -

<asp:datagrid id="dgla" OnItemCommand="declareDatagrid">
....
<Columns>
<ItemTemplate>
<asp:Literal id="lbOnLoan" Runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:Literal ID="lbTotalOnLoan" Runat="server" />
</FooterTemplate>
</columns>
</datagrid>

In the code behind I set the value of Literal.text when the datagrid is
bound.

On the same page that the datagrid is displayed I have a button that
when clicked sends an email - I have no problem coding the email
controls.

THE PROBLEM:
As part of the text of this email I want to include the VALUE that is
held the Literal.Text and I can't seem to extract it.

I think the solution is based on FINDCONTROL but I know that I am doing
something wrong.

Any solutions would be greatly appreciated.
 
N

nathan.cutmore

Thanks Scott, very useful and very much appreciated.

The code (VB.NET) solution you led me to was as follows -

Dim txt As Literal
Dim footerIndex As Integer

footerIndex = CType(dgla.Controls(0).Controls.Count - 1, Integer)
txt =
CType(dgla.Controls(0).Controls(footerIndex).FindControl("lbTotalcopiesHeld"),
Literal)
Response.Write(txt.Text)

As you can see from my first meassage:
dgla - is my is my datagrid id
lbTotalcopiesHeld - the literal id where the value is held

I hope others find this solution useful.
 
N

nathan.cutmore

Thanks Scott very useful and very much appreciated

The solution you led me to use (VB.NET) was -

Dim lit1 As Literal
Dim footerIndex1 As Integer

footerIndex1 = CType(dgla.Controls(0).Controls.Count - 1, Integer)
lit1 =
CType(dgla.Controls(0).Controls(footerIndex1).FindControl("lbTotalOnLoan"),
Literal)

response.write(lit1.Text)

Where 'dgla' is my Datagrid ID,, and 'lbTotalOnLoan' is the ID of the
Literal contained in the footer that holds the value I was trying to
extract.

I hope others find this simple solution useful.
 

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,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top