finding repeateritem which matches a fieldvalue

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there, I have a brain block on finding a repeater item which matches a
field from the row of the datasource. If my datasource has a column called
'somethingid' i want to find the repeateritem which has somethingid=1 (there
will only be one)

so I have set up an iterator

foreach (RepeaterItem item in myrepeater.Items)
{
//below is what i am trying to do but this doesnt work, not sure of syntax
if (item.dataitem["somethingid"]=="1") {

do something

}
}

Not sure what syntax to use. I'm sure its pretty simple. Thank you.
 
louise raisbeck said:
Hi there, I have a brain block on finding a repeater item which matches a
field from the row of the datasource. If my datasource has a column called
'somethingid' i want to find the repeateritem which has somethingid=1
(there
will only be one)

so I have set up an iterator

foreach (RepeaterItem item in myrepeater.Items)
{
//below is what i am trying to do but this doesnt work, not sure of syntax
if (item.dataitem["somethingid"]=="1") {

do something

}
}

Not sure what syntax to use. I'm sure its pretty simple. Thank you.

Most pages do something like this:

private void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Load data from the database
Page.DataBind();
}
}

In this case, RepeaterItem.DataItem will only be available during the
DataBind. In particular, it will not be available on PostBacks.

You'll have to create your own mechanism for associating database rows with
the ItemIndex of the RepeaterItem.

John Saunders
 
Repeater item is built from a template. It can be anything. It doesn't have
any properties for datasource. You need to know exactly what element in the
item template your column value lands on and navigate to that element.

Eliyahu
 
Back
Top