Hi Guys,
I encountered weird problem where the similar code runs well in one page and partially working on the other.
In both page, I have gridiview which has an edit command button. Page A is the working page, Page B partially working (can update the proj_name but not the from_date and to_date). Initially I used updatecommand to work on it but I just kept on giving me problem and it’s so hard to debug. So I use rowupdating event and it works for Page A and partially for Page B now. I have checked the sql query on this code, and it works fine in the database.
The problem is the asp:calendar in from_date and to_date are not getting updated on Page B. I have compared both codes of their aspx and aspx.vb and I can’t find where the problem is. Below are the relevant code from Page A and Page B. I hope you guys can help me with this as I believe many people are having similar problem with gridview updating. Thanks in advance
Below is the code for page A
Protected Sub agreementGrid_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles agreementGrid.RowUpdating
Dim maPackage, from_date, to_date, agreement_name, id As String
maPackage = e.NewValues.Item(“ma_package”)
id = e.Keys(0).ToString
‘Dim a As Integer = e.RowIndex
‘id = e.Keys.Item(1).ToString
from_date = e.NewValues.Item(“from_date”)
to_date = e.NewValues.Item(“to_date”)
agreement_name = e.NewValues.Item(“agreement_name”)
Dim strSql As String = “UpdateAgreement ” + “‘” + maPackage + “‘, ” + id + “,'” + from_date + “‘, ‘” + to_date + “‘, ‘” + agreement_name + “‘”
cmd = New SqlCommand(strSql)
UCConn.update(cmd)
agreementGrid.DataBind()
‘Response.Write(e.OldValues.Item(“ma_package”))
‘Response.Write(e.NewValues.Item(“ma_package”))
End Sub
And this is the code for Page B
No project belongs to this agreement
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
‘RegisterStartupScript(“from”, ““)If UCConn.checkSession = 1 Then
projectPanel.Visible = “false”
If Request(“cust_code”) <> “” Then
projectPanel.Visible = “true”
CustLbl.Text = Request(“cust_code”) + ” Projects”
End If
End Sub
Protected Sub ProjectGrid_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles ProjectGrid.RowUpdating
‘UpdateCommand=”update project set proj_name = @proj_name, from_date = @from_date, to_date = @to_date where proj_code = @proj_code”
Dim proj_name, from_date, to_date, proj_code As String
Dim from_dateA, to_dateA As String
from_dateA = e.OldValues.Item(“from_date”)
to_dateA = e.OldValues.Item(“to_date”)
proj_code = “‘” + e.Keys(0).ToString + “‘”
proj_name = “‘” + e.NewValues.Item(“proj_name”) + “‘”
from_date = “‘” + e.NewValues.Item(“from_date”) + “‘”
to_date = “‘” + e.NewValues.Item(“to_date”) + “‘”
‘proj_code = “‘” + e.OldValues.Item(“proj_code”) + “‘”
Dim strSql As String = “update project set proj_name = ” + proj_name + “, from_date = ” + from_date + “, to_date = ” + to_date + ” where proj_code = ” + proj_code
cmd = New SqlCommand(strSql)
UCConn.update(cmd)