简体   繁体   中英

c# asp.net repeater - create button based on condition

Basically what i would like to do is have a button which is only created for entries that have been flagged in a separate table for sending. So for example if i edit a record, i flag this other table and would like a send button to appear next to that record via the repeater below - is this possible? Can i do a check by calling a method for example unsure :(

<asp:Repeater ID="DepartmentsList" runat="server">
            <HeaderTemplate>
               <table id="grouptable" class="table table-bordered table-striped"> 
                <thead>
                        <tr>
                        <th>Send</th>
                        <th>ID</th>
                        <th>Name</th>
                        <th>Last Modified</th>
                        <th>Actions</th>
                    </tr>
                    </thead>
                    <tbody>
            </HeaderTemplate>
            <ItemTemplate>
                        <tr>
                        <td>
                        <input type="checkbox" name="sendSelect[]" value="<%# Eval("Dept_ID") %>"</input></td>
                        <td><%# Eval("Dept_ID") %></td>
                        <td><a href="<%# Eval("gURL") %>"><%# Eval("DESC") %></a> </td>
                        <td><%# Eval("CHG_DATE") %></td>
                        <td><a class="btn btn-info" href="<%# Eval("gURL") %>"><i class="icon-pencil icon-white"></i> Edit</a><asp:Button ID="Button1" runat="server" Text="Send" /></td>
                        </tr>
            </ItemTemplate>
            <FooterTemplate>
                        </tbody>
                </table>
            </FooterTemplate>
            </asp:Repeater>

You can do a check and inspect the current data record being bound to the repeater by using the DepartmentsList_OnItemDataBound event. It gives you all the power you need to dynamically change what's being bound and created in the repeater's item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM