Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Accessing TextBox from FooterTemplate

Posted on 2006-06-30
8
Medium Priority
?
432 Views
Last Modified: 2008-02-01
I have scenario where I need to be able to find and obtains values from a Server Control TextBox in a FooterTemplate and not ItemTemplate (which is the norm for everyone else).   I need to do this in postback meaning I need to find the control in some sort of collection and use the values.   But the problem is I can't seem to find the right collection to search through.   Like for Items in the ItemTemplate collection it's easy to find what I'm looking for.  I just do a for loop through the collection and then find the control i'm looking for.    But I don't know how to do this for an item/object in the FooterTemplate.    Anyone?   Here's the declarative code for the repeater I'm using with the object in the FooterTemplate:

<asp:Repeater ID="healthPlanGroupRepeater" Runat="server">
<HeaderTemplate>
            <table class="PBMDetailHealthPlanGroupSection" cellpadding="0" cellspacing"0" border="0" width="435">
                        <tr>                                            
                                    <td width="150">Group Name</td>
                                    <td width="10"><img height="1" src="Images/spacer.gif" width="10"></td>
                                    <td width="150">Group Id</td>
                                    <td width="10"><img height="1" src="Images/spacer.gif" width="10"></td>
                                    <td width="105">Cancel Date</td>
                                    <td width="10"><img height="1" src="Images/spacer.gif" width="10"></td>
                        </tr>
</HeaderTemplate>
<ItemTemplate>
                        <tr valign="top">
                                    <td><asp:TextBox Runat="server" id="groupNameTextBox"></asp:TextBox></td>
                                    <td><input type="hidden" runat="server" id="hiddenGroupUniqueIdentifier"/></td>
                                    <td><asp:TextBox Runat="server" id="groupIdTextBox"></asp:TextBox></td>
                                    <td></td>
                                    <td><picCalendar:Calendar ID="picGroupCancelDateTextBox" Runat="server" /></td>
                                    <td></td>
                        </tr>
</ItemTemplate>
<FooterTemplate>                                                        
                        <tr class="PBMDetailNewHealthPlanGroupSection">
                                    <td class="PBMDetailHealthPlanGroupHeader">Add Group</td>
                                    <td class="PBMDetailHealthPlanGroupSectionDivider"></td>
                                    <td><asp:TextBox ID="addHealthPlanGroupNameTextBox" Runat="server" /></td>
                                    <td><asp:TextBox ID="addHealthPlanGroupIdTextBox" Runat="server" /></td>
                                    <td></td>
                                    <td><picCalendar:Calendar ID="picAddHealthPlanGroupCancelDate" Runat="server" /></td>
                        </tr>                                          
            </table>                        
</FooterTemplate>      
</asp:Repeater>

So I want to be able to access the 'addHealthPlanGroupNameTextBox' TextBox in PostBack.  Thanks for your help!
0
Comment
Question by:calvinklein1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 4

Expert Comment

by:Kittrick
ID: 17019977
Hi there,
According to:
http://msdn.microsoft.com/library/?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolsrepeaterclasstopic.asp

"A Repeater binds its ItemTemplate and AlternatingItemTemplate to a data model declared and referenced by its DataSource property. The HeaderTemplate, FooterTemplate, and SeparatorTemplate are not data-bound."

This is going to make it tough to grab the data you want. I don't know if it's possible to put a second repeater on a page, but if it's possible, you could try that.

Kittrick

0
 
LVL 4

Expert Comment

by:Kittrick
ID: 17020033
You could also try in your footertemplate to grab the value stored in the itemtemplate of the box you want then hide the box in the <itemtemplate>.

You have:
<asp:TextBox ID="addHealthPlanGroupNameTextBox" Runat="server" />

in your footer template...but you could try:

<asp:TextBox ID="addHealthPlanGroupNameTextBox" Runat="server" text='<%# DataBinder.Eval(Container.DataItem, "the field to grab from itemtemplate")%>' />

then in the textbox you are grabbing the data from in the <itemtemplate>, you can hide by:

<asp:TextBox ID="addHealthPlanGroupNameTextBox" Runat="server" visible=false/>


so put together, it would look like this:

<repeater>
<itemtemplate>
<asp:TextBox ID="addHealthPlanGroupNameTextBox" Runat="server" visible=false/>

</itemtemplate>

<footertemplate>

<asp:TextBox ID="addHealthPlanGroupNameTextBox1" Runat="server" text='<%# DataBinder.Eval(Container.DataItem, "the field to
</footertemplate>
</repeater>

Hope that helps!
Kittrick
0
 

Author Comment

by:calvinklein1
ID: 17020072
It's an object that is filled in by the user not obtained from data collection.   This is a new row, data entry.  

This repeater is inside of another repeater so that does work.  I just didn't include all the code because it wasn't neccessary for this example.  

But I also saw what Microsoft has documented on this subject, but I have also read and heard people retrieving objects from the FooterTemplate or HeaderTemplate before.   I'm just not sure how they do it.   I thought by doing CType(repeaterItem.FindControl("healthPlanNameTextBox"), TextBox).Text  would give me the value of the TextBox but it doesn't appear to be working.   (That's yucky VB code by the way).    I think the reason why it's not working is because it's only looking in the ItemCollection rather than all the child controls within the Repeater control....
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:Kittrick
ID: 17020077
Sorry for posting again, but my example got cut off when I posted...

<repeater>
<itemtemplate>
<asp:TextBox ID="addHealthPlanGroupNameTextBox" Runat="server" visible=false/>

</itemtemplate>

<footertemplate>

<asp:TextBox ID="addHealthPlanGroupNameTextBox1" Runat="server" text='<%# DataBinder.Eval(Container.DataItem, "addHealthPlanGroupNameTextBox")%>'/>
</footertemplate>
</repeater>
0
 
LVL 4

Expert Comment

by:Kittrick
ID: 17020129
samtran0331 sorta solved what you are looking for at:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21502128.html

but the complete solution wasn't posted:(  but here's his code that iterates through child controls:


Dim i As Integer
        'outer repeater
        For i = 0 To Repeater1.Items.Count - 1
            Dim innerRepeater As Repeater = New Repeater
            innerRepeater = CType(Repeater1.Items(i).FindControl("childRepeater"), Repeater)
            Dim j As Integer
            For j = 0 To innerRepeater.Items.Count - 1
                'this is the inner loop?

            Next
        Next

0
 
LVL 4

Accepted Solution

by:
Kittrick earned 2000 total points
ID: 17020172
rafd123 created the following code at:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21025473.html

that will list all the controls on your page....I imagine you could go from there when trying to reference the one you are looking to have the user input into...

Private Sub ListControls(ByRef control As Control)
          'List each of the control's child controls
          For Each child As Control In control.Controls
               Trace.Warn("Unique ID :", child.UniqueID)
               'Recusively list all of the child's children
               ListControls(child)
          Next
     End Sub
0
 

Author Comment

by:calvinklein1
ID: 17020177
Found it.  I wasn't trying to find a repeater inside of another repeater.  I was trying to find an object within the FooterTemplate.
But I was concentrating too much on the Repeater Items rather than the Child Controls.

So I did this:

For i As Integer = 0 To healthPlanRepeater.Controls.Count - 1
            Dim addHealthPlanNameTextBox As TextBox = DirectCast(healthPlanRepeater.Controls.Item(i).FindControl("addHealthPlanNameTextBox"), TextBox)
            If Not (addHealthPlanNameTextBox Is Nothing) Then
                        If addHealthPlanNameTextBox.Text <> String.Empty Then
                                    Dim DoSomething As String = addHealthPlanNameTextBox.Text
                        End If
            End If
Next

Thanks for your help on this though.  i'll give you the points.
0
 

Author Comment

by:calvinklein1
ID: 17020183
ooo you got to it before I could post it.  hahaha. nice.  thanks again!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question