Again, on click of the Save button, postback occurs and gv1.DataBind is called. Databind should then go through the RowDataBound event but does not. Where am I going wrong?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Session("DeptID") = 1 'FOR TESTING ONLY
'populate Process dropdown
ddlProcess_Load()
pnlJobForm.Visible = False
btnSave.Visible = False
Else 'not is postback
If pnlJobForm.Visible = True Then
BindData()
End If
End If
End Sub
Protected Sub ddlProcess_Load()
'populate Process dropdown (where Process has ControlFormReq = true)
standard code here
End Sub
Protected Sub ddlProcess_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlProcess.SelectedIndexChanged
'populate JobRef dropdown
End Sub
Protected Sub ddlJobRef_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlJobRef.SelectedIndexChanged
Session("JobID") = ddlJobRef.SelectedValue
Session("JobRef") = ddlJobRef.SelectedItem.Text
GetDataSet()
End Sub
Private Sub GetDataSet()
Dim iProcessID, iJobID As Integer
iProcessID = Session("ProcessID")
iJobID = Session("JobID")
'stored proc will check to see if any answers exist (return 0),
'if no answers, will return questions only (return 1)
Dim db As SqlDatabase = New SqlDatabase(sConn)
Dim cmd As DbCommand = db.GetStoredProcCommand("BD_GetControlData")
db.AddInParameter(cmd, "@iProcessID", SqlDbType.Int, iProcessID)
db.AddInParameter(cmd, "@iJobID", SqlDbType.Int, iJobID)
Dim ds As DataSet
ds = db.ExecuteDataSet(cmd)
Dim iCount As Integer = ds.Tables(0).Rows.Count
If iCount < 1 Then
lblMsg.Text = "No control form questions available for this Process."
lblMsg.Visible = True
pnlJobForm.Visible = False
lblJobRef.Visible = False
btnSave.Visible = False
Exit Sub
Else
Session("Questions") = ds
pnlJobForm.Visible = True
btnSave.Visible = True
lblJobRef.Text = "JOB REF: " + Session("JobRef")
lblJobRef.Visible = True
BindData()
'check for existing control form answers
cmd = db.GetStoredProcCommand("BD_GetNewControlForm")
db.AddInParameter(cmd, "@iProcessID", SqlDbType.Int, iProcessID)
db.AddInParameter(cmd, "@iJobID", SqlDbType.Int, iJobID)
ds.Clear()
ds = db.ExecuteDataSet(cmd)
iCount = ds.Tables(0).Rows.Count
If iCount < 1 Then
lblMsg.Text = "NEW CONTROL FORM: Please click the SAVE button when done."
lblMsg.Visible = True
Else
lblMsg.Text = "Please click the SAVE button after making changes."
lblMsg.Visible = True
End If
End If
End Sub
Public Sub BindData()
Dim ds As DataSet
ds = Session("Questions")
ds.Tables(0).TableName = "Questions"
gv1.DataSource = ds
gv1.DataMember = "Questions"
gv1.DataBind() 'PROBLEM - DOES NOT GO TO ROWDATABOUND ON POSTBACK
End Sub
Public Sub gv1_RowDataBound(ByVal sender As System.Object, ByVal e As GridViewRowEventArgs) Handles gv1.RowDataBound
If e.Row.RowType = ListItemType.Item Or e.Row.RowType = ListItemType.AlternatingItem Then
'code that loads each row here...works great IF called
End Sub
Protected Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
'this goes through the rows and saves the user entered values -- it too works fine IF the gridview does thru databind...rowdatabound method.
End Sub