Alaa
Alaa

Reputation: 217

Using Repeater control in vb.net

I am using a repeater control to view database table data, I want to add a link button next to each row to delete a specific row, how can I do that using vb.net??

Upvotes: 1

Views: 7170

Answers (1)

Ram Singh
Ram Singh

Reputation: 6918

There is nothing to do much, do you want to display it(link button for all the rows? if yes then try the following code)

<table cellpadding="0" cellspacing="0">
                        <tr valign="top" class="list_heading">
                            <td width="25%">
                                Column
                            </td>
                            <td width="25%">
                                Operation
                            </td>
                            <td width="19%" style="display: none;">
                                And/Or
                            </td>
                            <td width="25%">
                                Value
                            </td>
                            <td width="06%">
                                Remove
                            </td>
                        </tr>
                        <tbody>
                            <asp:Repeater ID="rpSearchItems" runat="server">
                                <ItemTemplate>
                                    <tr>
                                        <td style="display: none;">
                                        </td>
                                        <td>
                                            <%# Eval("ColumnName") %>
                                        </td>
                                        <td>
                                            <%# Eval("Operation") %>
                                        </td>
                                        <td style="display: none;">
                                            <%# Eval("AndOr") %>
                                        </td>
                                        <td>
                                            <%# Eval("Value") %>
                                        </td>
                                        <td align="center">
                                            <asp:ImageButton ID="ibtnRemoveSearchItem" ImageUrl="~/Controls/ImagesForSearch/Remove.png"
                                                CommandArgument=' <%# Eval("Id") %>' CssClass="RemoveUitem" ToolTip="Remove Item"
                                                runat="server" OnClick="ibtnRemoveSearchItem_Click" />
                                        </td>
                                    </tr>
                                </ItemTemplate>
                            </asp:Repeater>
                        </tbody>
                        <tr valign="top" class="list_bottom">
                            <td colspan="6">
                                &nbsp;
                            </td>
                        </tr>
                    </table>

And in code behind code you can go like this:

Protected Sub ibtnRemoveSearchItem_Click(sender As Object, e As EventArgs)
 ImageButton ibtnRemoveSearchItem = (ImageButton)sender;
    Int32 Id = Convert.ToInt32(ibtnRemoveSearchItem.CommandArgument);
//Using the above two lines you can get the Coomand Argument, pass it to you delete stored proc thats all
// do your stuff here
End Sub

hope this will help you

UPDATE : If you want to add it conditionally then you can do it from "OnItemDataBound" event of repeater

for much info review this

This one also can help you

Upvotes: 1

Related Questions