Referencing Controls in Data Repeater using C#.Net

Posted on 2009-12-23
Last Modified: 2013-12-17
Good Afternoon,

I'm looking for some assistance with a Data Repeater in

The repeater I have contains an item template that has the the following code...

                        <asp:Button ID="btnEdit" runat="server" Text="Edit" Width="50px" />
                        <asp:Label ID="lblLanguage" runat="server" Text=<%#DataBinder.Eval(Container.DataItem,"Language")%> />
                        <asp:Label ID="lblRegion" runat="server" Text=<%#DataBinder.Eval(Container.DataItem,"Region")%> />
                        <asp:Label ID="lblMsg_ID" runat="server" Text=<%#DataBinder.Eval(Container.DataItem,"Msg_ID")%> />
                        <asp:TextBox ID="txtPriority" runat="server" Width="40px" Text=<%#DataBinder.Eval(Container.DataItem,"Priority")%> />

My question is that the txtPriority control gets populated with an integer from SQL Server per item in the repeater.

I need to be able to allow a user to click a save button after updating any of these values, and then I need to be able to reference each of the values, and update them in their respective records in the database.

The problem is that I can't reference txtPriority directly because it obviously does not use the same control id multiple times in the page.

If anyone can assist me with this issue it would be most highly appreciated.

Thank you in advance for your time!
Question by:tsqlguy
    LVL 41

    Expert Comment

    It actually depends where you want to access that control.
    The idea is to find control in the repeater item
    could be in ItemDataBound event
    TextBox tbpriority = (TextBox) e.Item.FindControl("txtPriority);

    TextBox tbpriority = Repeater1.Items[0].FindControl("txtPriority");

    or if in a loop pass the index instead of '0' in above.
    LVL 3

    Author Comment

    When I try to do the following...

    TextBox tbpriority = rptGrid.Items[1].FindControl("txtPriority");

    I get this error:

    Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.TextBox'. An explicit conversion exists (are you missing a cast?)

    Thanks Guru Sami
    LVL 41

    Accepted Solution

    my bad...should be casting the second one as well...

    TextBox tbpriority = (TextBox) rptGrid.Items[1].FindControl("txtPriority");
    LVL 3

    Author Closing Comment

    Thanksha Guru Sami

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now