Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate Details View

Status
Not open for further replies.

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.
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()
 
I am not sure why you are creating a gridview and detailsview in the rowdatabound of gvEmpDbound. It seems those controls exist on your page and you are assigning them to your newly created variables, dg and gv.
I'm not sure if that is part of the problem becuse they are createdin that event, and that event would need to fire to show the changes..
I guess I need some clarification on what you are trying to do.

Jim
 
Im just dim dv and gv so I wouldn't have to write out the whole control name when I did the findcontrol.
I was going to use the gv but i ended up not using that and forgot to take it out.

As for what I am trying to do

I have a gridview that brings up an employee record that record
has name address phone etc.
The DetailsView is for inserting new dependents based on the employee's id. Some of the info the detailsview has is Address,Phone,firstname,lastname etc. So I am trying to prevent the user from reentering that data. Instead i populate those fields based on the information contained in the gridview. I used a textbox for these in the detailsview because it is possible that the user may need to change the info. Maybe they have a child that has a different last name or something and they may need to change that.
I am just trying to auto populate the detailsview fields as much as possible
 
Im just dim dv and gv so I wouldn't have to write out the whole control name when I did the findcontrol
That creates a new instance of your control. So, you are updating data in dv, and not dvNewDepend.
 
so even though i did
Code:
Dim dv As DetailsView = dvNewDepend
it creates a new control?
What would be the best way to accomplish what i am trying to accomplish?

Thanks
 
I'm not sure if that is part of the problem becuse they are createdin that event, and that event would need to fire to show the changes..

I cause that event to fire when an item is inserted from the detailsview
Code:
 Protected Sub dvNewDepend_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles dvNewDepend.ItemInserted
        gvEmployee.DataBind()
 
it creates a new control?
What would be the best way to accomplish what i am trying to accomplish?
Yes it creates a copy of the control...
Just reference the control by name dvNewDepend.
 
If i do this
Code:
  Dim dgi As DviewDep

I get this
BC30002: Type 'DviewDep' is not defined

I really just want to find out why the detailsview is not populating except on page load.
 
Where are you poupulating the grid? Is it in the page load? Let's see the code.
 
the code is in my first post, It just binds with whatever the default setting are for a gridview.
I have it bind again when the detailsview does an insert
 
that is the rowdatabound event.. where do you call the databind method?
 
when the item is inserted
Code:
  Protected Sub dvNewDepend_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles dvNewDepend.ItemInserted
        gvEmployee.DataBind()
 
There is no vb code for the bind other than when the detailsview item is inserted. Other than that It is just bound with whatever the default is for Asp.Net 2.0 Gridview control.
The gridview is populated based on a querystring parameter that it gets from a link on another page.
 
You'll have to find someway to refresh your datasource, maybe the Select method? I figured the databind would have done that for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top