LINQ - How to synchronize records between FormView and ListView?

Asked By Dale H on 09-Feb-12 07:34 PM
I'm using linqdatasource to display a single record in a formview and want to have a listview or detailsview show the record(s) that match a particular field in the Formview.  This field is the primary key to the table I wish to display in the listview or details view.  As the user pages through the formview (read only) I want to display the appropriate record(s).  I've tried QueryString parameters, Control parameters but nothing works.  If I put an actual record id in the defaultvalue, I do get data.  In other word, I just want to sync the two forms... 
Somesh Yadav replied to Dale H on 14-Feb-12 06:15 AM
Hi,
    in your ItemDataBound of your ListView, do this please:

    Protected Sub ItemCommand(ByVal sender As Object, ByVal e As       System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ListView1.ItemCommand   
        Dim tb1, tb2, tb3 As TextBox   
        Dim ddl1 As DropDownList   
    
        tb1 = CType(e.Item.FindControl("txtpkey"), TextBox)   
        tb2 = CType(e.Item.FindControl("txthaulkey"), TextBox)   
        tb3 = CType(e.Item.FindControl("txtmileage"), TextBox)   
        ddl1 = CType(e.Item.FindControl("editsurfaceddl"), DropDownList)   
    
        If e.CommandName = "Update" Then  
    
          Dim Mystrsql As String = "UPDATE rmfhaulsurface SET Surface = '"  
          Mystrsql &= ddl1.Text & "', Mileage = '" & tb3.Text.Trim   
          Mystrsql &= "' WHERE pkey = " & tb1.Text   
    
          haulsurfacedata.UpdateCommand = Mystrsql   

           ……………………………………

         ElseIf e.CommandName=="Edit" Then

         ListView1.EditIndex = e.Item.ItemIndex;

         ListView1.DataBind();

          ………………
 Hope it helps you.