Wednesday 18 April 2012

ASP.NET Template Field Command Triggering

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                     OnRowCommand="GridView1_RowCommand">
                        <Columns>
                            <asp:BoundField DataField="ID" HeaderText="ID" Visible="False" />
                            <asp:BoundField HeaderText="Field Name" DataField="CurrencyName" >
                            </asp:BoundField>
                                                   
                             <asp:TemplateField ShowHeader="False">
                                 <ItemTemplate>
                                     <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="false" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID")%>'
                                         CommandName="ItemDelete" ImageUrl="~/Admin/Img/Delete.png" Text="Button" />
                                 </ItemTemplate>
                                 <ItemStyle Width="18px" />
                            </asp:TemplateField>
                            
                        </Columns>
                  </asp:GridView>


    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
        Dim MyPool As New LogicPool.DB("Conn")
        If (e.CommandName = "ItemDelete") Then

            Dim index As Integer = Convert.ToInt32(e.CommandArgument)
            MyPool.SQLRun("DELETE FROM AppCurrencyRules WHERE ID = " & index)
            FillGrid()
        End If
    End Sub

No comments:

Post a Comment