Datagrid kontrolü yardimiyla kayit düzenlemeupdatecancel ve delete islemleri - Papatyam Forum

Papatyam Forum

Go Back   Papatyam Forum > ..::.BİLGİSAYAR & TEKNOLOJİ.::. > Web Master > asp.net

Yeni Konu aç  Cevapla
 
Seçenekler
Alt 29 March 2008, 13:01   Mesaj No:1

tamerr89

Papatyam Paylaşımcı Üyesi
Avatar Otomotik
Durumu:tamerr89 isimli Üye şimdilik offline konumundadır
Papatyam No : 1196
Üyelik T.: 09 December 2007
Arkadaşları:0
Cinsiyet:
Yaş:34
Mesaj: 212
Konular:
Beğenildi:
Beğendi:
Takdirleri:10
Takdir Et:
Konu Bu  Üyemize Aittir!
Standart Datagrid kontrolü yardimiyla kayit düzenlemeupdatecancel ve delete islemleri

Datagrid kontrolü yardimiyla kayit düzenlemeupdatecancel ve delete islemleri

<%@ 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&quot)

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&quot & ";"
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&quot
MyDataGrid.Datasource=ds.Tables("kisiler&quot .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&quot)


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&quot & ";"
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">
<aspataGrid id="MyDataGrid" runat="server" DataKeyField="kisi_id" OnPageIndexChanged="Page_Change" OnDeleteCommand="MyDataGrid_DeleteCommand&quo t; OnUpdateCommand="MyDataGrid_UpdateCommand&quo t; OnCancelCommand="MyDataGrid_Cancelcommand&quo t; 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>
</aspataGrid>
</div>
<!-- Insert content here -->
</form>
</body>
</html>

Alıntı ile Cevapla
Cevapla

Bookmarks

Konuyu Toplam 1 Üye okuyor. (0 Kayıtlı üye ve 1 Misafir)
 

Benzer Konular
Konu Başlıkları Konuyu Başlatan

Papatyam Forum Ana Kategori Başlıkları

Cevaplar Son Mesajlar
Kayit yapma tamerr89 visual basic.net 0 29 March 2008 18:08
Asp.net ile veri tabanina kayit tamerr89 asp.net 0 29 March 2008 13:02
Ado.net ile datagrid 1 tamerr89 ADO.NET-ADO 0 08 February 2008 17:30
Ado.net ile datagrid 2 tamerr89 ADO.NET-ADO 0 08 February 2008 17:29
Yazilma sonrasi islemleri > upload..... tamerr89 CGI 0 08 February 2008 17:21

Yeni Sayfa 1

www.papatyam.org Ana Sayfa

Tefekküre Davet Köşesi

Papatyam Sosyal Medya Guruplarımıza Katılın

                       Instagram         

Papatyam alemdarhost.com sunucularında barındırılmaktadır.