Datagrid kontrolü yardimiyla kayit düzenleme, updatecancel ve delete islemleri. - ASP.NET Webmaster bilgi bankası, knowledge base Webmaster Araçları

AnaSayfa > ASP.NET > Datagrid kontrolü yardimiyla kayit düzenleme, updatecancel ve delete islemleri.
Kategori: ASP.NET
Gönderen: Admin
Tarih: 2008-11-11
Puan: 1   Puan:1 | Katılımcı:5 | Katılımcı : 5
Okunma: 4022
  
 
1 puan 2 puan 3 puan 4 puan 5 puan 6 puan 7 puan 8 puan 9 puan 10 puan

<%@ Page Language="VB" Debug="true" CodePage="28599" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="system.data.oledb" %>
<script runat="server">

<%-- sub binddata()

Dim con As OleDbConnection
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; DATA Source=" & Server.MapPath("uyeler.mdb"))

con.Open()

Dim komut As OleDbCommand
komut = New OleDbCommand("select * from kisiler", con)

Dim alinan_veri As OleDbDataReader

alinan_veri = komut.ExecuteReader()

MyDataGrid.DataSource = alinan_veri
MyDataGrid.DataBind()

con.close()

end sub --%>

Sub BindData()
Dim strConn as String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("\uyeler.mdb") & ";"
Dim MySQL as string = "Select * from kisiler Order by kisi_id asc"
Dim MyConn as New OleDbConnection(strConn)
Dim ds as DataSet=New DataSet()
Dim Cmd as New OleDbDataAdapter(MySQL,MyConn)
Cmd.Fill(ds,"kisiler")
MyDataGrid.Datasource=ds.Tables("kisiler").DefaultView
MyDataGrid.DataBind()
End Sub

Sub Page_Load(sender As Object, e As EventArgs)
If not page.Ispostback then
binddata()
end If
End Sub

Sub MyDataGrid_EditCommand(s As Object, e As DataGridCommandEventArgs )
MyDataGrid.EditItemIndex = e.Item.ItemIndex
BindData()
End Sub

Sub MyDataGrid_Cancelcommand(Source As Object, E As DataGridCommandEventArgs)
MyDataGrid.EditItemIndex = -1
BindData()
End Sub

Sub MyDataGrid_UpdateCommand(s As Object, e As DataGridCommandEventArgs )

Dim conn As OleDbConnection
conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; DATA Source=" & Server.MapPath("uyeler.mdb"))


Dim MyCommand As oledbCommand

'Dim txtid As textbox = E.Item.cells(1).Controls(0)
Dim txtadi_sadi As textbox = E.Item.cells(2).Controls(0)
Dim txtemail As textbox = E.Item.cells(3).Controls(0)
Dim txttelefon As textbox = E.Item.cells(4).Controls(0)


Dim strUpdateStmt As String
strUpdateStmt ="UPDATE kisiler SET" & _
" kisi_id =@id, kisi_adi_soyadi =@adi_sadi, kisi_email =@email, kisi_telefon =@tel where kisi_id = @id"

MyCommand = New oledbCommand(strUpdateStmt, conn)

MyCommand.Parameters.Add(New oledbParameter("@id", e.item.cells(1).text))
MyCommand.Parameters.Add(New oledbParameter("@adi_sadi", txtadi_sadi.text))
MyCommand.Parameters.Add(New oledbParameter("@email", txtemail.text))
MyCommand.Parameters.Add(New oledbParameter("@tel", txttelefon.text))

conn.Open()
MyCommand.ExecuteNonQuery()
MyDataGrid.EditItemIndex = -1
conn.close
BindData()

End Sub

Sub Page_Change(sender As Object, e As DataGridPageChangedEventArgs)
MyDataGrid.CurrentPageIndex = e.NewPageIndex
BindData
End Sub

Sub MyDataGrid_DeleteCommand(s As Object, e As DataGridCommandEventArgs )
Dim strConn as String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("\uyeler.mdb") & ";"
Dim DeleteCmd As String = "DELETE from kisiler Where kisi_id = @ID"
Dim MyConn as New OleDbConnection(strConn)
Dim Cmd as New OleDbCommand(DeleteCmd, MyConn)
Cmd.Parameters.Add(New OleDbParameter("@ID", MyDataGrid.DataKeys(CInt(e.Item.ItemIndex))))
MyConn.Open()
Cmd.ExecuteNonQuery()
MyConn.Close()
BindData
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<div align="center">
<asp:DataGrid id="MyDataGrid" runat="server" DataKeyField="kisi_id" OnPageIndexChanged="Page_Change" OnDeleteCommand="MyDataGrid_DeleteCommand" OnUpdateCommand="MyDataGrid_UpdateCommand" OnCancelCommand="MyDataGrid_Cancelcommand" OnEditCommand="MyDataGrid_EditCommand" CellPadding="2" BorderColor="Maroon" BorderWidth="1px" width="50%" AutoGenerateColumns="False" Font-Size="X-Small" Font-Names="Tahoma">
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" HeaderText="düzenle" CancelText="Cancel" EditText="<img src=edit.gif border=0 width=12 height=12>"></asp:EditCommandColumn>
<asp:BoundColumn DataField="kisi_id" ReadOnly="True" HeaderText="Kişi ID"></asp:BoundColumn>
<asp:BoundColumn DataField="kisi_adi_soyadi" HeaderText="adı soyadı"></asp:BoundColumn>
<asp:BoundColumn DataField="kisi_email" HeaderText="e-mail"></asp:BoundColumn>
<asp:BoundColumn DataField="kisi_telefon" HeaderText="telefon"></asp:BoundColumn>
<asp:ButtonColumn Text="<img src=delete.gif border=0 width=12 height=12>" HeaderText="Sil" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:DataGrid>
</div>
<!-- Insert content here -->
</form>
</body>
</html>



Yorumlar
Henüz Kimse Yorum Yapmamış, ilk yorumu siz ekleyin!
Yorum Ekleme Aparatı
Yorum Eklemek için lütfen sol menuden giris yapınız..
Toplam 0 yorum listelendi.