Datagrid

Datagrid (tr) Datagrid kontrolü yardımıyla kayıt düzenleme&güncelleme ve silme işlemleri.Kodları .aspx uzantılı kayıt edip ASP.NET sunucusunda çalıştırmanız yeterlidir. Dim con As OleDbConnectioncon = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; DATA Source=" & Server.MapPath("uyeler.mdb"))con.Open()Dim komut As OleDbCommandkomut = New OleDbCommand("select * from kisiler", con)Dim alinan_veri As OleDbDataReaderalinan_veri = komut.ExecuteReader()MyDataGrid.DataSource = alinan_veriMyDataGrid.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").DefaultViewMyDataGrid.DataBind()End SubSub Page_Load(sender As Object, e As EventArgs)If not page.Ispostback thenbinddata()end IfEnd SubSub MyDataGrid_EditCommand(s As Object, e As DataGridCommandEventArgs )MyDataGrid.EditItemIndex = e.Item.ItemIndexBindData()End SubSub MyDataGrid_Cancelcommand(Source As Object, E As DataGridCommandEventArgs)MyDataGrid.EditItemIndex = -1BindData()End SubSub MyDataGrid_UpdateCommand(s As Object, e As DataGridCommandEventArgs )Dim conn As OleDbConnectionconn = 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 StringstrUpdateStmt ="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 = -1conn.closeBindData()End SubSub Page_Change(sender As Object, e As DataGridPageChangedEventArgs)MyDataGrid.CurrentPageIndex = e.NewPageIndexBindDataEnd SubSub 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()BindDataEnd Sub " CancelText="Cancel" HeaderText="düzenle" UpdateText="Update" ButtonType="LinkButton">">

Döküman Arama

Başlık :

Kapat