473,385 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Updating details view programmatically

34
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
Aug 16 '07 #1
7 7400
kenobewan
4,871 Expert 4TB
Please provide more information. Thanks.
Aug 16 '07 #2
teju
34
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.
Aug 18 '07 #3
kenobewan
4,871 Expert 4TB
You may be having a postback problem. Using page.ispostback sometimes resolves this type of issue. HTH.
Aug 18 '07 #4
teju
34
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. //Onclick button call the grid view which is populated using sql datsource
  3.  Protected Sub btsearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btsearch.Click
  4.         Dim search = txtsearch.Text
  5.         Dim quervar = Request.QueryString("search")
  6.         Response.Write("loop for button clicked<br>")
  7.  End Sub
  8. //Called when linkbutton button is clicked on the gridview to display the details
  9.  
  10.     Sub populatedetails(ByVal search, ByVal quervar)
  11.         Dim myCommand As New SqlCommand("sp_XXX", MyConnection)
  12.         myCommand.CommandType = Data.CommandType.StoredProcedure
  13.         myCommand.Parameters.Add(New SqlParameter("@strModule", SqlDbType.NVarChar, 1000)).Value = search
  14.         Response.Write("loop for populate")
  15.         Dim myAdapter As New SqlDataAdapter(myCommand)
  16.         myCommand.Connection.Open()
  17.         myCommand.ExecuteNonQuery()
  18.  
  19.         Dim DS As New DataSet
  20.         myAdapter.Fill(DS)
  21.  
  22.         DetailsView1.DataSource = DS
  23.         DetailsView1.DataBind()
  24.         myCommand.Connection.Close()
  25.  
  26.     End Sub
  27. //OnItemCommand
  28.     Protected Sub ChangeDetails(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewCommandEventArgs) Handles DetailsView1.ItemCommand       
  29.  
  30.  If (e.CommandName.Equals("Update")) Then
  31. //Calls function for update          
  32.   UpdateDetailsView()
  33.         End If
  34.  
  35.  
  36.  
  37.     End Sub
  38. //Update Function
  39. //HOW DO I CHANGE THE DETAILS VIEW TO READ MODE AFTER UPDATE
  40.     Sub UpdateDetailsView()
  41.         Dim supId As HttpCookie
  42.         supId = Request.Cookies("SSMCODE")
  43.         Dim sup = supId.Value
  44.  
  45.         If Not (IsPostBack) Then
  46.             Response.Write("hello")
  47.  
  48.  
  49.         End If
  50.  
  51.     End Sub
  52.  
  53.  
  54.     Sub CustomerDetailsView_ModeChanging(ByVal sender As Object, ByVal e As DetailsViewModeEventArgs)
  55.         Response.Write("loopfor modechanged<br>")
  56.         Dim supId As HttpCookie
  57.         supId = Request.Cookies("SSMCODE")
  58.         Dim sup = supId.Value
  59.         Dim search = txtsearch.Text
  60.         Dim quervar = Request.QueryString("search")
  61.         DetailsView1.ChangeMode(e.NewMode)
  62.         If e.NewMode = DetailsViewMode.Edit Then
  63.             DetailsView1.AllowPaging = False
  64.         End If
  65.         populatedetails(sup, quervar)
  66.     End Sub
  67.  
  68.     Sub chkcancel(ByVal sender As Object, ByVal e As DetailsViewInsertEventArgs)
  69.         e.Cancel = True
  70.     End Sub
  71.  
  72. //called ondatabound
  73.     Sub popdrp(ByVal sender As Object, ByVal e As EventArgs)
  74.         Dim supId As HttpCookie
  75.         supId = Request.Cookies("SSMCODE")
  76.         Dim sup = supId.Value
  77.  
  78.         If DetailsView1.CurrentMode = DetailsViewMode.Edit Then
  79.             Response.Write("loop for edit databound<br>")
  80.  
  81.             Dim drp2 As DropDownList = CType(Me.DetailsView1.FindControl("drporganiser2"), DropDownList)
  82.             Dim drp3 As DropDownList = CType(Me.DetailsView1.FindControl("DropDownList1"), DropDownList)
  83.             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"
  84.             Dim myCommand2 As New SqlCommand(str, MyConnection)
  85.  
  86.  
  87.             Dim DR As SqlDataReader = myCommand2.ExecuteReader()
  88.             If DR.HasRows Then
  89.                 DR.Read()
  90.  
  91.                 Dim objvalue = DR.GetValue(0)
  92.  
  93.                 If objvalue = "" Then
  94.  
  95.                     Response.Write(objvalue)
  96.                     drp3.Visible = True
  97.                     drp2.Visible = False
  98.                     drp2.Enabled = False
  99.  
  100.  
  101.                 Else
  102.  
  103.                     drp2.Visible = True
  104.                     drp3.Visible = False
  105.  
  106.  
  107.                 End If
  108.             End If
  109.  
  110.         End If
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.     End Sub
  119.  
  120. //Called From Grid VIEW
  121.     Public Sub LinkButton_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
  122.  
  123.         Dim quervar = Request.QueryString("search")
  124.         er = e.CommandArgument
  125.         Response.Cookies("SSMCODE").Value = er
  126.  
  127.         populatedetails(er, quervar)
  128.     End Sub
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
I hope this explains my problem. After hunting so many things now IAm totally confused.

MANY THANKS FOR YOUR HELP
Aug 20 '07 #5
teju
34
Hello,
Please, if anyone could help me out.
Many Thanks,
Teju
Aug 21 '07 #6
kenobewan
4,871 Expert 4TB
This isn't your code is it? You need to engage in some debugging. HTH.
Aug 21 '07 #7
teju
34
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.
Aug 21 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Pete | last post by:
One way to accomplish thumbnail imaging without excessive lines of code is using the web browswer control (see WebBrowseWeb form in Solutions.mdb). The trouble is when I point to a directory path...
2
by: Nanda | last post by:
hi, i have an editable datagrid. how can i update the database, When the user completes entering data for a row. i.e., data should be updated whenever user completes entering a row. Thanks in...
0
by: willow1480 | last post by:
I am developing a small little Service Control Application. I am using a listview control with checkboxes and getting the list of services I want to control from a text file. When you check a...
2
by: MikeY | last post by:
Hi Everyone, I'm having problems with my syntax on the updating part for the Northwind.MDB. All other code seems fine. It has to do with the Order Details on the thisAdapter.Update( ). Or I...
0
by: MikeY | last post by:
Hi Everyone, (Just doing a repost case my previous post was too far down the line, sorry fro the repost) I'm having problems with my syntax on the updating part for the Northwind.MDB. All other...
3
by: John Morgan | last post by:
I have my first small SQl Server 2005 database developed on my local server and I have also its equivalent as an online database. I wish to update the local database (using and asp.net interface)...
2
by: Rich Raffenetti | last post by:
In the listview control I can set the highlighted item with listview.focus() listview.items(integerValue).selected=true How do I programmatically scroll the pane of the details view to bring...
4
by: randy.buchholz | last post by:
Been fighting this one for a while, looking for help. I have a simple page with a grid view and details view (just managing a single table). The details view is primarily used for creating new...
0
by: Mike | last post by:
So here's the situation (.NET 2.0 btw): I have a form, and on this form is a textbox among many other databound controls. The textbox is bound to a field in a data table via the Text property. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.