<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
	protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e) {
		int id = (int)DataList1.DataKeys[e.Item.ItemIndex];
		SqlDataSource1.DeleteParameters["IDcategoria"].DefaultValue = id.ToString();
		SqlDataSource1.Delete();
	}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:nwind%>"
            SelectCommand="SELECT CategoryID, CategoryName, Description FROM Categories"
            DeleteCommand="DELETE FROM [Categories] WHERE [CategoryID] = @IDcategoria">
            <DeleteParameters>
                <asp:Parameter Type="Int32" Name="IDcategoria"></asp:Parameter>
            </DeleteParameters>
        </asp:SqlDataSource>
        <asp:DataList ID="DataList1"  runat="server" DataKeyField="CategoryID" DataSourceID="SqlDataSource1"
            OnDeleteCommand="DataList1_DeleteCommand">
            <ItemStyle Font-Names="Verdana" Font-Size="X-Small" />
            <ItemTemplate>
                <%# ((DataRowView)Container.DataItem)["CategoryID"]%>
                -
                <%# ((DataRowView)Container.DataItem)["CategoryName"]%>
                <br />
                <%# ((DataRowView)Container.DataItem)["Description"]%>
                <asp:Button ID="btnSelect" Text="Excluir" CommandName="delete" runat="server" />
            </ItemTemplate>
        </asp:DataList>
    </div>
    </form>
</body>
</html>
