DetailsView Nesnesinde
Insert,Update,Delete İşlemleri
Merhaba arkadaşlar. Bu makalemizde Detailsview nesnesinde Insert, Update, Delete işlemlerini göreceğiz.
Şekil 2 deki gibi tabloyu seçtikten sonra Advanced a tıklayın.
Şekil 2
Açılan pencerede Generate Insert, Update and Delete Statements i seçip Ok butonuna tıklayın(Şekil 3).
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False" CellPadding="4" DataKeyNames="ID" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Height="50px" Width="178px">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
<EditRowStyle BackColor="#999999" />
<FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
<Fields>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="JobTitle" HeaderText="JobTitle" SortExpression="JobTitle" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="CountryRegion" HeaderText="CountryRegion" SortExpression="CountryRegion" />
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />
</Fields>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE
FROM [Customers] WHERE [ID] = ?" InsertCommand="INSERT
INTO [Customers] ([ID], [LastName], [FirstName], [JobTitle], [City],
[CountryRegion]) VALUES (?, ?, ?, ?, ?, ?)" ProviderName="<%$
ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT
[ID], [LastName], [FirstName], [JobTitle], [City], [CountryRegion] FROM
[Customers]" UpdateCommand="UPDATE
[Customers] SET [LastName] = ?, [FirstName] = ?, [JobTitle] = ?, [City] = ?,
[CountryRegion] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="JobTitle" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="CountryRegion" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="JobTitle" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="CountryRegion" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
Bir makalenin daha sonuna geldik. Bir sonraki makalede
görüşmek üzere. Bahadır ŞAHİN