reference item in repeater itemTemplate   from code behind failed, asp.net 2.0

tomcattyy
tomcattyy used Ask the Experts™
on
Hello there,
I need to reference items in the itemTemplate, I have search one sample in EE but for someone reason not work in my case. Can you take a look?
Basically I want to collect information from the textBox after postback, but I just cannot find the correct way. Appreciate your help.
aspx
 
 <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" >
        <ItemTemplate>
           
            <table id="editing" class="reqChange" cellspacing="0">  
            <tr><td>
                <asp:Label ID="Label1" runat="server" Visible ="false"></asp:Label>
            </td></tr>         
            <tr><td colspan ="10">Customer Information</td></tr>
             <tr><td colspan ="10">--------------------------</td></tr>
            <tr class ="acct_info">
            <td>Account:</td><td class="acct_info">
                <%# Eval("corr")+"-"+Eval("office")+"-"+Eval ("acct_no") %></td><td>Account Name:</td><td class="acct_info"><%#Eval("acct_name") %></td><td>Status:</td><td class="acct_info"><%#Eval("status") %></td>
            <td>Capacity:</td><td class="acct_info"><%#Eval("capacity") %></td><td>Company:</td><td class="acct_info"><asp:TextBox ID="company" Text ='<%#Eval ("company") %>' runat="server"></asp:TextBox></td>
            </tr>
            <tr class ="acct_info">
            <td>Entity:</td><td class ="acct_info"><%#Eval("legal_entity") %></td><td>SSN last4:</td><td class ="acct_info"><%# getSSN(Eval ("ssn").ToString ()) %></td><td >Marital status:</td><td class ="acct_info"><asp:TextBox ID="marital" Text ='<%#Eval ("marital_status") %>' runat="server"></asp:TextBox></td><td>Birthday:</td><td class ="acct_info"><%#getBirth ( Eval ("dob").ToString ()) %></td>
            <td>Day Trader:</td><td class ="acct_info"><asp:TextBox ID="day_trader" Text ='<%#Eval ("day_trader") %>' runat="server"></asp:TextBox></td>
            </tr>
            <tr class ="acct_info">
            <td>Address:</td><td class ="acct_info"><asp:TextBox ID="add1" Text ='<%#Eval ("add1") %>' runat="server"></asp:TextBox></td>
            <td>Address2:</td><td class ="acct_info"><asp:TextBox ID="add2" Text ='<%#Eval ("add2") %> ' runat="server"></asp:TextBox></td><td>City:</td><td class ="acct_info"><asp:TextBox ID="city" Text ='<%# Eval ("city") %>' runat="server"></asp:TextBox></td><td >Zip code:</td><td class ="acct_info"><asp:TextBox ID="zip" Text ='<%#Eval ("zip") %>' runat="server"></asp:TextBox></td><td>Country:</td><td class ="acct_info"><asp:TextBox ID="country" Text ='<%#Eval ("country") %>' runat="server"></asp:TextBox></td>            
            </tr>
            <tr class ="acct_info">            
            <td>Phone:</td><td class ="acct_info"><asp:TextBox ID="phone" Text ='<%#Eval ("Phone") %>' runat="server"></asp:TextBox> </td><td>Fax:</td><td class ="acct_info"><asp:TextBox ID="fax" Text ='<%# Eval ("fax") %>' runat="server"></asp:TextBox></td><td >Email:</td><td class ="acct_info"><asp:TextBox ID="email" Text ='<%#Eval ("email") %>' runat="server"></asp:TextBox></td><td></td><td ></td><td></td><td ></td>
            </tr>
            <tr class ="acct_info">           
            <td>Joint name:</td><td class ="acct_info"><asp:TextBox ID="jt_name" Text ='<%#Eval ("jt_name") %>' runat="server"></asp:TextBox></td><td>Joint ssn 4digit</td><td class ="acct_info"><%# getSSN(Eval ("jt_ssn").ToString ()) %></td><td >Joint Relationship:</td><td class ="acct_info"><asp:TextBox ID="jt_mnr_relation" Text ='<%#Eval ("jt_mnr_relation") %>' runat="server"></asp:TextBox></td><td>Joint DOB:</td><td class ="acct_info"><%#getBirth ( Eval ("jt_mnr_dob").ToString ()) %></td>            
             <td></td><td ></td>
            </tr>
             <tr class ="acct_info">
            <td>Mail address:</td><td class ="acct_info"><asp:TextBox ID="mailadd1" Text ='<%#Eval("mail_add1") %>' runat="server"></asp:TextBox></td><td>Mail address2:</td><td class ="acct_info"><asp:TextBox ID="mailadd2" Text ='<%# Eval ("mail_add2") %>' runat="server"></asp:TextBox></td><td >Mail City:</td><td class ="acct_info"><asp:TextBox ID="mailcity" Text ='<%#Eval ("mail_city") %>' runat="server"></asp:TextBox></td><td>Mail state:</td><td class ="acct_info"><asp:TextBox ID="mailst" Text ='<%#Eval ("mail_st_cd") %>' runat="server"></asp:TextBox></td>
            <td>Mail zip code:</td><td class ="acct_info"><asp:TextBox ID="mailzip" Text ='<%#Eval ("mail_zip") %>' runat="server"></asp:TextBox></td>
            </tr>
            <tr class ="acct_info">
            <td>Mail country:</td><td class ="acct_info"><asp:TextBox ID="mailcountry" Text ='<%#Eval("mail_country") %>' runat="server"></asp:TextBox></td><td></td><td ></td><td >W8 / W9:</td><td class ="acct_info">W<%# Eval ("w8w9") %></td><td></td><td ></td>
            <td></td><td ></td>
            </tr>
            <tr><td> 
                <asp:Image ID="reqSend" ImageUrl="img/request_btn_send.png" runat="server" /> </td><td></td><td><asp:Button ID="Button2" runat="server" Text="Close" /></td></tr>
            </table>
            
        </ItemTemplate>
        </asp:Repeater>
 
 
cs code
 
protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!Page.IsPostBack)
{
}
else 
{
            TextBox tb = (TextBox)Repeater1.FindControl("company");
            Response.Write (tb.Text);
...... more for other fields
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Digital Marketing (Hospitality)
Commented:
Hi tomcattyy,
Your record may be more than one that binded into the repeater control. Try refer the control using a loop event to check the captured value.
eg:
for (int i = 0; i <= Repeater1.Items.Count - 1; i++) {
TextBox tb = (TextBox) Repeater1.Items(i).FindControl("company");
            Response.Write (tb.Text);
//remaining logic....
}

Author

Commented:
Thanks x_com, worked as you expected.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial