gtjr921
Programmer
- Aug 30, 2006
- 115
I have a page that has a GridView and Details view on it.
the detailsview is only used for Inserting, thus my default mode is set to insert.
I created a VB Sub that populates some of the detailsview fields with data from the gridview.
All that works great when the page is first loaded,
once I insert the detailsview data and the page postsback the
fields in the detailsview are no longer populated with the dynamic data from the gridview.
Here is my relevent code.
the detailsview is only used for Inserting, thus my default mode is set to insert.
I created a VB Sub that populates some of the detailsview fields with data from the gridview.
All that works great when the page is first loaded,
once I insert the detailsview data and the page postsback the
fields in the detailsview are no longer populated with the dynamic data from the gridview.
Here is my relevent code.
Code:
'Find the Address,LastName and Phone of Employee in
'Gridview and populate the Detailsview controls with that 'data
Protected Sub gvEmpDbound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles gvEmployee.RowDataBound
Dim dv As DetailsView = dvNewDepend
Dim gv As GridView = gvEmployee
Dim EmpIDVar As Int32 = Request.QueryString("EmpID")
If e.Row.RowType = DataControlRowType.DataRow Then
EmpLastNM = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Last_Nm"))
EmpAddress = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "address"))
EmpPhone = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "hmphone"))
End If
Dim LastNM As TextBox = dv.FindControl("TxtLastNM")
Dim Address As TextBox = dv.FindControl("TxtAddress")
Dim Phone As TextBox = dv.FindControl("TxtPhone")
Dim lblEmpID As Label = dv.FindControl("lblEmpID")
lblEmpID.Text = EmpIDVar
LastNM.Text = EmpLastNM
Address.Text = EmpAddress
Phone.Text = EmpPhone
End Sub
'added these lines to see if binding the data would 'repopulate 'the details view to no avail
Protected Sub dvNewDepend_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles dvNewDepend.ItemInserted
gvEmployee.DataBind()