Find controls in a Repeater

Ø

Øyvind Isaksen

I have a Repeater that dynamicly displayes some textboxes. Each Textbox has
an ID like this (example): ID="10_20_textbox". The first number (10)
describes what article this field is for, and the secound number (20)
describes what article attribute this belongs to. In my code I need to loop
through all the Items in my Repeater Control.

My question is: Is it possible to use "FindControl" when the ID is
dynamically generated (find part of ID, like "_textbox" in my example)? I
need to loop througt all controls in my repeater, and get the text,
ArticleID and ArticleAttributeID and add this to my collection.

Here is my code:


foreach (RepeaterItem Item in this.repAttributes.Items)
{
int varArticleID = Item.FindControl..?... Find TextBox ID, Split and get
the first number before "_"...

int varAttributeID = Item.FindControl..?... Find TextBox ID, Split and
get the secound number after "_"...

string varContent = item.FindControl..?... Find the Text value for this
textbox...

ArticleAttribute.ArticleId = varArticle
ArticleAttribute.ArticleAttribute = varAttributeID
ArticleAttribute.Content = varContent

ArticleAttributeCollection.Add(ArticleAttribute)
}

SaveAttributes(ArticleAttributeCollection)
 
G

Guest

Check the textbox's ID for the expected pattern:

foreach (RepeaterItem ri in repAttributes.Items)
{
foreach (Control c in ri.Controls)
{
if (c is TextBox)
{
if (c.ID.EndsWith ("_textbox", StringComparison.CurrentCulture)
{
// Do work...
}
}
}
}
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top