Programalama > ASP.NET

Etiketler: datagrid

Ort. 1
Puan ver:
<%@ 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&#252;zenle" CancelText="Cancel" EditText="&lt;img src=edit.gif border=0 width=12 height=12&gt;"></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="&lt;img src=delete.gif border=0 width=12 height=12&gt;" HeaderText="Sil" CommandName="Delete"></asp:ButtonColumn>
                </Columns>
            </asp:DataGrid>
        </div>
        <!-- Insert content here -->
    </form>
</body>
</html>


Yorumlar                 Yorum Yaz
Bu hazır kod'a ilk yorumu siz yapın!
KATEGORİLER
ASP - 240
ASP.NET - 24
C# - 75
C++ - 174
CGI - 8
DELPHI - 247
FLASH - 49
HTML - 536
PASCAL - 246
PERL - 11
PHP - 160
WML - 9
XML - 2
Copyright © 2002 - 2024 Hazır Kod - Tüm Hakları Saklıdır.
Siteden yararlanırken gizlilik ilkelerini okumanızı tavsiye ederiz.
hazirkod.com bir İSOBİL projesidir.