0

So, I have two lists with the same type of objects. One of the list contains every single object of that type from the database. The other list contains only objects that have a specific ID.

I have a repeater which lists all objects from the first list in one column, and checkboxes for each item in the second column. What I'm trying to do now is to automatically check the checkboxes for items that are members in both lists, meaning that if an item in list2 also exists in list1, then the checkbox next to that item in the Table should be checked.

I've been searching for a solution for hours now with no luck, and I'm hoping someone can help me with this.

Thanks in advance!

This is the frontend code:

<asp:Repeater runat="server" ID="BegreppRepeater">
    <HeaderTemplate>
        <table class="adminObjectsTable">
            <th>Begrepp</th>
            <th></th>

    </HeaderTemplate>
    <ItemTemplate>

        <tr>
            <td><%#DataBinder.Eval(Container.DataItem, "name") %></td>
            <td><input type="checkbox" name="checkbox1" value=""></td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>
CobraAn
  • 43
  • 6

1 Answers1

0

Have you tried looking at the ItemDataBound Event for the Repeater? You can look at both values there and check the CheckBox on that row according to the values.

To make things even easier, you could potentially add the value true false to your sql statement and use what is returned to set the value of the checkbox. See this article to understand the sql for that approach:

How to select the comparison of two columns as one column in Oracle

Also, check out this article that addresses your issue pretty well:

how to check the checkbox inside the repeater at binding time accordingto value?

Community
  • 1
  • 1
Trajan Unger
  • 121
  • 5
  • Yes, I've tried, but I can't seem to get it working. So far I've tried a foreach loop that checks if an object in list2 also exists in list1, but I've been unable to bind that to a specific row in the Repeater and thereby check that rows checkbox. – CobraAn May 19 '14 at 19:35
  • I'm using two different sp's to populate the lists, one that gets all objects from the db table, and one that gets objects based on the input ID. The problem is that I need every object from the table to show in the repeater, but I also need to check those that are linked to a specific ID which is forwarded as a parameter from the previous page (this is the edit page of an object). EDIT: I've looked at that solution but I didn't work out for me. – CobraAn May 19 '14 at 19:45
  • Sorry, it is not clear what the actual problem is. Can you not compare the two values in the ItemDataBound Event and then check the box accordingly? – Trajan Unger May 19 '14 at 19:51
  • Sorry, forgot to get back to you. I managed to solve the problem after some time, thanks for your help! – CobraAn Jun 02 '14 at 09:19
  • Glad to help. Care to share your solution? – Trajan Unger Jun 03 '14 at 19:46