Updating details view programmatically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • teju
    New Member
    • Jul 2006
    • 34

    Updating details view programmatically

    Hello All,
    I am having trouble while updating the detailsview. The onItemcommand executes twice.
    Could anyone please help .
    It is driving me insane

    Thanks,
    Teju
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Please provide more information. Thanks.

    Comment

    • teju
      New Member
      • Jul 2006
      • 34

      #3
      Hello ,
      I am using details view prgrammatically using code behind to poulate and perform other operations on detailsview.

      for editing data i am using modechanging event and while clicking on the update button i am calling onitemcommand.

      When i click the update button it call onitemcommand and checks for command name=Update
      then i retrieve the text box values which are changed in the edit mode and try to print it just for testing whether it gets corrects values, I realised that it is printing twice, so i think some how it is executing twice as no where other than that iam using response.write

      I hope iam making sense, if not i will post my code on monday.

      Thanks for helping.

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        You may be having a postback problem. Using page.ispostback sometimes resolves this type of issue. HTH.

        Comment

        • teju
          New Member
          • Jul 2006
          • 34

          #5
          Hello,
          Thanks, for your concerned reply, it does seems to sort out the problem.
          But when i click on save button or the update button, it should get back to read mode. I do use chage mode even t once the details are updated.
          It pops up with error details view cannot change mode while it is updating . I am posting my code behind on VB file for your reference.

          Code:
          [B]//Onclick button call the grid view which is populated using sql datsource[/B]
           Protected Sub btsearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btsearch.Click
                  Dim search = txtsearch.Text
                  Dim quervar = Request.QueryString("search")
                  Response.Write("loop for button clicked<br>")
           End Sub
          [B]//Called when linkbutton button is clicked on the gridview to display the details[/B]
          
              Sub populatedetails(ByVal search, ByVal quervar)
                  Dim myCommand As New SqlCommand("sp_XXX", MyConnection)
                  myCommand.CommandType = Data.CommandType.StoredProcedure
                  myCommand.Parameters.Add(New SqlParameter("@strModule", SqlDbType.NVarChar, 1000)).Value = search
                  Response.Write("loop for populate")
                  Dim myAdapter As New SqlDataAdapter(myCommand)
                  myCommand.Connection.Open()
                  myCommand.ExecuteNonQuery()
          
                  Dim DS As New DataSet
                  myAdapter.Fill(DS)
          
                  DetailsView1.DataSource = DS
                  DetailsView1.DataBind()
                  myCommand.Connection.Close()
          
              End Sub
          [B]//OnItemCommand[/B]
              Protected Sub ChangeDetails(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewCommandEventArgs) Handles DetailsView1.ItemCommand       
          
           If (e.CommandName.Equals("Update")) Then
          //Calls function for update          
            UpdateDetailsView()
                  End If
          
          
          
              End Sub
          [B]//Update Function
          //HOW DO I CHANGE THE DETAILS VIEW TO READ MODE AFTER UPDATE[/B]
              Sub UpdateDetailsView()
                  Dim supId As HttpCookie
                  supId = Request.Cookies("SSMCODE")
                  Dim sup = supId.Value
          
                  If Not (IsPostBack) Then
                      Response.Write("hello")
          
          
                  End If
          
              End Sub
          
          
              Sub CustomerDetailsView_ModeChanging(ByVal sender As Object, ByVal e As DetailsViewModeEventArgs)
                  Response.Write("loopfor modechanged<br>")
                  Dim supId As HttpCookie
                  supId = Request.Cookies("SSMCODE")
                  Dim sup = supId.Value
                  Dim search = txtsearch.Text
                  Dim quervar = Request.QueryString("search")
                  DetailsView1.ChangeMode(e.NewMode)
                  If e.NewMode = DetailsViewMode.Edit Then
                      DetailsView1.AllowPaging = False
                  End If
                  populatedetails(sup, quervar)
              End Sub
          
              Sub chkcancel(ByVal sender As Object, ByVal e As DetailsViewInsertEventArgs)
                  e.Cancel = True
              End Sub
          
          [B]//called ondatabound[/B]
              Sub popdrp(ByVal sender As Object, ByVal e As EventArgs)
                  Dim supId As HttpCookie
                  supId = Request.Cookies("SSMCODE")
                  Dim sup = supId.Value
          
                  If DetailsView1.CurrentMode = DetailsViewMode.Edit Then
                      Response.Write("loop for edit databound<br>")
          
                      Dim drp2 As DropDownList = CType(Me.DetailsView1.FindControl("drporganiser2"), DropDownList)
                      Dim drp3 As DropDownList = CType(Me.DetailsView1.FindControl("DropDownList1"), DropDownList)
                      Dim str = "SELECT distinct ssm_organisers.Organiser_Name,ssms.Organiser2_Code FROM ssm_organisers INNER JOIN ssms ON ssm_organisers.idStaff = ssms.Organiser2_Code where ssms.SSM_Code='" & sup & "' order by ssm_organisers.Organiser_Name asc"
                      Dim myCommand2 As New SqlCommand(str, MyConnection)
          
          
                      Dim DR As SqlDataReader = myCommand2.ExecuteReader()
                      If DR.HasRows Then
                          DR.Read()
          
                          Dim objvalue = DR.GetValue(0)
          
                          If objvalue = "" Then
          
                              Response.Write(objvalue)
                              drp3.Visible = True
                              drp2.Visible = False
                              drp2.Enabled = False
          
          
                          Else
          
                              drp2.Visible = True
                              drp3.Visible = False
          
          
                          End If
                      End If
          
                  End If
                         
          
          
          
          
          
          
              End Sub
          
          [B]//Called From Grid VIEW[/B]
              Public Sub LinkButton_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
          
                  Dim quervar = Request.QueryString("search")
                  er = e.CommandArgument
                  Response.Cookies("SSMCODE").Value = er
                 
                  populatedetails(er, quervar)
              End Sub
          I hope this explains my problem. After hunting so many things now IAm totally confused.

          MANY THANKS FOR YOUR HELP

          Comment

          • teju
            New Member
            • Jul 2006
            • 34

            #6
            Hello,
            Please, if anyone could help me out.
            Many Thanks,
            Teju

            Comment

            • kenobewan
              Recognized Expert Specialist
              • Dec 2006
              • 4871

              #7
              This isn't your code is it? You need to engage in some debugging. HTH.

              Comment

              • teju
                New Member
                • Jul 2006
                • 34

                #8
                Originally posted by kenobewan
                This isn't your code is it? You need to engage in some debugging. HTH.
                I didn't get you when you said this isn't your code. My question is how do i change the mode in detailsview after clicking update button to readonly back
                I tried databind method, disabling view state but none of them works.

                Comment

                Working...