locked
how to paging in datagrid of edit records....! RRS feed

  • Question

  • User-909305153 posted

     i want to do paging in datagrid of edit records.....!

     this is my code.kindly solve my problem as soon as possible....!

     

    <%@ Import Namespace="System.Data.OleDb" %>

     <Script Runat="Server">

         Dim conNorthwind As OleDbConnection

         Dim cmdSql As OleDbCommand

    Dim strSql As String

     Sub Page_Load

             conNorthwind = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _
                  & "DATA SOURCE=" _
                      & Server.MapPath("nwind.mdb;"))

    If Not IsPostBack Then

    BindDataGrid

    End If

    End Sub

     Sub BindDataGrid

             cmdSql = New OleDbCommand("Select * From login", conNorthwind)

    conNorthwind.Open()

             dgrdlogin.DataSource = cmdSql.ExecuteReader()
             dgrdlogin.DataBind()

    conNorthwind.Close()

    End Sub

         Sub dgrdlogin_EditCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs)

             dgrdlogin.EditItemIndex = e.Item.ItemIndex

             BindDataGrid()

         End Sub

         Sub dgrdlogin_UpdateCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs)

             Dim intmyID As Integer

             Dim txtusername As TextBox

             Dim strusername As String
            
             Dim txtpw As TextBox

             Dim strpw As String
            
            
             Dim txtfirstname As TextBox

             Dim strfirstname As String
            
             Dim txtlastname As TextBox

             Dim strlastname As String
            
            

             intmyID = dgrdlogin.DataKeys(e.Item.ItemIndex)

             txtfirstname = e.Item.Cells(1).Controls(0)

             strfirstname = txtfirstname.Text
            
             txtpw = e.Item.Cells(4).Controls(0)

             strpw = txtpw.Text
            
             txtusername = e.Item.Cells(3).Controls(0)

             strusername = txtusername.Text
            
             txtlastname = e.Item.Cells(2).Controls(0)

             strlastname = txtlastname.Text
            
            
            

             strSql = "Update login Set firstname=@firstname, lastname=@lastname, username=@username, pw=@pw  " _
             & " Where ID=@myID"

             cmdSql = New OleDbCommand(strSql, conNorthwind)
            
            

             cmdSql.Parameters.Add("@firstname", strfirstname)
            
             cmdSql.Parameters.Add("@lastname", strlastname)

          
            

             cmdSql.Parameters.Add("@username", strusername)
            
             cmdSql.Parameters.Add("@pw", strpw)

             cmdSql.Parameters.Add("@myID", intmyID)

             conNorthwind.Open()

             cmdSql.ExecuteNonQuery()

             conNorthwind.Close()

             dgrdlogin.EditItemIndex = -1

             BindDataGrid()
             Response.Write("update successfully") 'kindly put here the label
            

         End Sub

         Sub dgrdlogin_CancelCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs)

             dgrdlogin.EditItemIndex = -1

             BindDataGrid()

         End Sub

     </Script>

     <html>

    <head><title>ExpertDataGridEditlogin.aspx</title></head>

    <body>

    <form id="Form1" Runat="Server">

     <asp:DataGrid

    ID="dgrdlogin"

    OnEditCommand="dgrdlogin_EditCommand"

    OnUpdateCommand="dgrdlogin_UpdateCommand"

    OnCancelCommand="dgrdlogin_CancelCommand"

    DataKeyField="ID"

    AutoGenerateColumns="False"

    CellPadding="10"

    HeaderStyle-BackColor="LightGrey"

    Runat="Server" BackColor="White">

    <Columns>

    <asp:BoundColumn

    HeaderText="Employee ID"

    DataField="ID"

    ReadOnly="True" />

    <asp:BoundColumn

    HeaderText="First Name" DataField="firstname" />

    <asp:BoundColumn

    HeaderText="Last Name" DataField="lastname" />


    <asp:BoundColumn

    HeaderText="User Name" DataField="username" />

    <asp:BoundColumn

    HeaderText="Password" DataField="pw" />

    <asp:EditCommandColumn

    EditText="Edit!"

    UpdateText="Update!"

    CancelText="Cancel!" />


     



    </Columns>
         <HeaderStyle BackColor="LightGray" />
        
       

    </asp:DataGrid>



     

     </form>

    </body>

    </html>
     

    Monday, September 15, 2008 8:44 AM

Answers

  • User-927253188 posted
    For your data grid add attributes

    AllowPaging="True" PagerSettings-Mode="NumericFirstLast"

    After that in "PageIndexChanging" event of the gridview add below line :

    <<GridName>>.PageIndex = e.NewPageIndex

    After that again call the logic to bind the grid again.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 15, 2008 8:56 AM

All replies

  • User-927253188 posted
    For your data grid add attributes

    AllowPaging="True" PagerSettings-Mode="NumericFirstLast"

    After that in "PageIndexChanging" event of the gridview add below line :

    <<GridName>>.PageIndex = e.NewPageIndex

    After that again call the logic to bind the grid again.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 15, 2008 8:56 AM
  • User-909305153 posted

    kindly add your line in my code i will be very thankful for u...!

    plz....! 

    Monday, September 15, 2008 9:02 AM