finding repeateritem which matches a fieldvalue

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.
 
J

John Saunders

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
 
E

Eliyahu Goldin

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
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top