conditions in a repeater

college_amy

Regular
Joined
Jan 3, 2004
Messages
83
I am using a repeater and a dataset to retrieve / display data from a database.

The data consists of a few fields one of which being a Type field that contains either a 0 or a 1 depending on the type of data in the record.

I want, with only the one trip to the db, to extract all the records. Which I did. But after the records are retrieved, I want to sort them based on type and only certain rows be displayed in a certain format with the repeater.

For example:

<asp:repeater>

<itemtemplate>

<tr <%databinder stuff “type” == 1%>>

<td>Type 1 Name:<%databinder stuff “name”%> *only those names with type=1 display here </td>

</tr>

<tr <%databinder stuff “type” == 0%>>

<td>Type 0 Name: <%databinder stuff “name” %> *only those names with type=0 display here </td>

</tr>

</itemtemplate>

</asp:repeater>



The condition is where I am having the problem. Because the data is arranged in such a way, I am having difficulty displaying the data with conditions. I only want the names of a certain person to show in the first row if their type == 1. Like wise for the second row I only want them to show the names of the people who’s types are 0.

I know there is a bunch of stuff missing from the above example – but I do have it all there in the code. I hope you understand and know a solution for this without making numerous trips to the db and without having multiple repeaters.

Any help is appreciated.
 
Found my own answer - so if anyone else needs it... here it is:
<asp:TableRow runat=server Visible='<%#(DataBinder.Eval(Container.DataItem, "Conditional_field_if_int").ToString()=="1")%>' >
<asp:TableCell Runat="server">Name:
</asp:TableCell>
<asp:TableCell Runat="server"><%# DataBinder.Eval(Container.DataItem, "Name") %></asp:TableCell>
<asp:TableCell Runat="server">Email:</asp:TableCell>
<asp:TableCell Runat="server"><%# DataBinder.Eval(Container.DataItem, "Email") %></asp:TableCell>
<asp:TableCell Runat="server">Phone:</asp:TableCell>
<asp:TableCell Runat="server"><%# DataBinder.Eval(Container.DataItem, "Phone") %></asp:TableCell>
</asp:TableRow>

The conditional field that i am checking in dataset is of type int. So it must be converted to a string before I can check to see if the two match.
Hope that helps someone else.
 
Back
Top