472,129 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,129 software developers and data experts.

Gridview Databind does not go to RowDataBound event on postback?

K B
Hi again, I've narrowed down my problem and am hoping to get some help
to get the final answer.

Gridview with dynamic child controls loads
gv1.Databind calls RowDataBound event fine

On the next postback, I use gv1.Databind in order to reload the dynamic
rows but Databind does NOT call RowDataBound event -- it skips right to
the button click event that called the postback.

Any clues please?

Thanks,
Kit
*** Sent via Developersdex http://www.developersdex.com ***
May 31 '06 #1
3 10206
"K B" <ka**********@comcast.net> wrote in message
news:ec**************@TK2MSFTNGP05.phx.gbl...
Hi again, I've narrowed down my problem and am hoping to get some help
to get the final answer.

Gridview with dynamic child controls loads
gv1.Databind calls RowDataBound event fine

On the next postback, I use gv1.Databind in order to reload the dynamic
rows but Databind does NOT call RowDataBound event -- it skips right to
the button click event that called the postback.

Any clues please?


Is the code which binds your GridView wrapped in a if(Page.IsPostBack) logic
loop...?
May 31 '06 #2
K B <ka**********@comcast.net>'s wild thoughts were released
on Tue, 30 May 2006 18:29:26 -0700 bearing the following
fruit:
Hi again, I've narrowed down my problem and am hoping to get some help
to get the final answer.

Gridview with dynamic child controls loads
gv1.Databind calls RowDataBound event fine

On the next postback, I use gv1.Databind in order to reload the dynamic
rows but Databind does NOT call RowDataBound event -- it skips right to
the button click event that called the postback.

Any clues please?


may need to see your code

Jan Hyde (VB MVP)

--
Is it fair to say that there'd be less litter in Britain if blind people were given pointed sticks?

Jun 1 '06 #3
KitB40
1
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
Jun 1 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by ryan.mclean | last post: by
1 post views Thread by =?Utf-8?B?V2VzbGV5IERhdmlzLCBHZW5lcmFsIER5bmFtaWNz | last post: by
1 post views Thread by =?Utf-8?B?cmxt?= | last post: by
3 posts views Thread by COHENMARVIN | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.