Datagrid Inline question

Silly1

New member
Joined
May 16, 2005
Messages
4
Programming Experience
3-5
with the Datagrid Edit Inline, I am able to edit (display textboxes), cancel and update a value (with a inline value)

When I read in the value from the
e.Items.Cells(1).Text the old value are display and not the new ones which I typed in.

the code looks standard for a simple inline edit. Can you look at it and let me know what you think, even if you do not see anything wrong with it. I have gone over this code enough to memorize it.

Thanks for any help.

and please even if it looks standard can you reply atleast I will know that my code is correction.

All fields are bound columns.

The first column is the Edit link.

well that's all ....

:)

VB.NET:
Imports System
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Configuration

Public Class JMDataGrid
    Inherits System.Web.UI.Page


#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents dgDG As System.Web.UI.WebControls.DataGrid

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        BindData()
    End Sub

    Private Sub dgDG_edit(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgDG.EditCommand
        dgDG.EditItemIndex = e.Item.ItemIndex
        BindData()
    End Sub

    Private Sub dgDG_cancel(ByVal cource As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgDG.CancelCommand
        dgDG.EditItemIndex = -1
        BindData()
    End Sub


    Private Sub dgDG_update(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgDG.UpdateCommand
        Dim txtJobKey As TextBox = e.Item.Cells(1).Controls(0)
        Dim txtJobNo As TextBox = e.Item.Cells(2).Controls(0)



        'Retrieve the updated values
        Dim iJobKey As String = txtJobKey.Text
        Dim iJobNo As String = txtJobNo.Text


        Dim strConnection As New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))

        Dim UpdSql As String = "UPDATE Job_Mgmt_Summ SET JobNo = '" & iJobNo & "' Where JobKey = '" & iJobKey & "'"



        'command to get value
        Dim myCmd As New SqlCommand(UpdSql, strConnection)

        myCmd.Connection.Open()

        'myCmd.CommandText = CommandType.Text
        myCmd.ExecuteNonQuery()

        BindData()

        dgDG.EditItemIndex = -1

    End Sub

    Sub BindData()

        'Connection created
        Dim strConnection As New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))

        'command object to pass the string
        Const strSQL As String = "Select JobKey as mJobKey, JobNo as mJobNo, JobName as mJobName, JobAdd as mJobAdd, JobCity as mJobCity, JobSt as mJobSt,JobZip as mJobZip, JobStart as mJobStart, JobEnd as mJobEnd, JobOpen as mJobOpen From Job_Mgmt_Summ WHERE (JobOpen = N'OPEN')"

        'command to get value
        Dim myCmd As New SqlCommand(strSQL, strConnection)

        myCmd.CommandText = strSQL


        strConnection.Open()
        dgDG.DataSource = myCmd.ExecuteReader(CommandBehavior.CloseConnection)
        dgDG.DataBind()

    End Sub
End Class




 
Back
Top