• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 479
  • Last Modified:

Referencing ASP.net Controls in Data Repeater using C#.Net

Good Afternoon,

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

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

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

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!
0
tsqlguy
Asked:
tsqlguy
  • 2
  • 2
1 Solution
 
guru_samiCommented:
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
e.g.
TextBox tbpriority = (TextBox) e.Item.FindControl("txtPriority);

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

or if in a loop pass the index instead of '0' in above.
0
 
tsqlguyAuthor Commented:
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
0
 
guru_samiCommented:
my bad...should be casting the second one as well...

TextBox tbpriority = (TextBox) rptGrid.Items[1].FindControl("txtPriority");
0
 
tsqlguyAuthor Commented:
Thanksha Guru Sami
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now