Find controls in a Repeater

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Øyvind Isaksen

    Find controls in a Repeater

    I have a Repeater that dynamicly displayes some textboxes. Each Textbox has
    an ID like this (example): ID="10_20_textb ox". 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 "FindContro l" 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 ArticleAttribut eID and add this to my collection.

    Here is my code:


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

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

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

    ArticleAttribut e.ArticleId = varArticle
    ArticleAttribut e.ArticleAttrib ute = varAttributeID
    ArticleAttribut e.Content = varContent

    ArticleAttribut eCollection.Add (ArticleAttribu te)
    }

    SaveAttributes( ArticleAttribut eCollection)


  • =?Utf-8?B?U2l2YSBN?=

    #2
    RE: Find controls in a Repeater

    Check the textbox's ID for the expected pattern:

    foreach (RepeaterItem ri in repAttributes.I tems)
    {
    foreach (Control c in ri.Controls)
    {
    if (c is TextBox)
    {
    if (c.ID.EndsWith ("_textbox", StringCompariso n.CurrentCultur e)
    {
    // Do work...
    }
    }
    }
    }

    "Øyvind Isaksen" wrote:
    I have a Repeater that dynamicly displayes some textboxes. Each Textbox has
    an ID like this (example): ID="10_20_textb ox". 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 "FindContro l" 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 ArticleAttribut eID and add this to my collection.
    >
    Here is my code:
    >
    >
    foreach (RepeaterItem Item in this.repAttribu tes.Items)
    {
    int varArticleID = Item.FindContro l..?... Find TextBox ID, Split and get
    the first number before "_"...
    >
    int varAttributeID = Item.FindContro l..?... Find TextBox ID, Split and
    get the secound number after "_"...
    >
    string varContent = item.FindContro l..?... Find the Text value for this
    textbox...
    >
    ArticleAttribut e.ArticleId = varArticle
    ArticleAttribut e.ArticleAttrib ute = varAttributeID
    ArticleAttribut e.Content = varContent
    >
    ArticleAttribut eCollection.Add (ArticleAttribu te)
    }
    >
    SaveAttributes( ArticleAttribut eCollection)
    >
    >
    >

    Comment

    Working...