Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb_dotnet thread: DataGrid - Update Problem - HELP


Message #1 by "Robert Sindall" <robert@t...> on Wed, 24 Apr 2002 16:32:54 +0100
This is a multi-part message in MIME format.

------=_NextPart_000_0098_01C1EC65.2FF25FF0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

MessageI am still new to ASP.NET but here is something that may help.  
ASP pages are loaded every time a trip is made to the server.  If you 
load the datagrid in the page_load event jandler, you may be ocerwriting 
your updates.  The page object has a property named:  page.IsPostBack  
that can help.  If IsPostBack is false, then the page is being loaded 
for the very first time, if true the page is being loaded ater server 
side processing after some client side processing took place (like the 
changes you describe).  Protect the initialization logic by placing it 
inside a IF block like:

Private Sub Page_Load(ByVal sender As System.Object, ByVCal e as 
System.EventArgs) Handles MyBase.Load
    'Fill a text  with initial value only upon the first request.
    If not IsPostBack then
        txtFirstName.Text =3D "Please enter your name"   ' This is where 
you need to place your grid initializtion logic
    End If
End Sub

In ASP.NET the Page_Load is like the Form_Activated event of VB.NET 
which has the same problem, but VB.NET lacks the build in flag to 
indicate that the form is being rebuilt just because the form became 
visible after it was covered up or not the active form for a brief 
time...
  ----- Original Message -----
  From: Robert Sindall
  To: pro_VB_dotnet
  Sent: Wednesday, April 24, 2002 8:32 AM
  Subject: [pro_vb_dotnet] DataGrid - Update Problem - HELP


  Hi

  it worked once... when I was using e.item.itemindex instead of 
e.item.cells(0).text

  it seems to work, but once its saved it, it shows me the old data. 
there is no error msg.

  the datagrid has columns like this:

  Id | Username | Password | Edit

  Id is readonly.

  whats wrong with this code ?!?



  Private Sub AdminUserGrid_UpdateCommand(ByVal source As Object, ByVal 
e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles 
AdminUserGrid.UpdateCommand

  Dim UpdateAdminUser As Obsessed.AdminUserDB =3D New 
Obsessed.AdminUserDB()

  Dim Id As Integer =3D CType(e.Item.Cells(0).Text, Integer)

  Dim UsernameTxt As TextBox =3D CType(e.Item.Cells(1).Controls(0), 
TextBox)

  Dim PasswordTxt As TextBox =3D CType(e.Item.Cells(2).Controls(0), 
TextBox)

  'this class updates the admin user table
  UpdateAdminUser.UpdateAdminUser(CInt(Id), CStr(UsernameTxt.Text), 
CStr(PasswordTxt.Text))

  AdminUserGrid.EditItemIndex =3D -1

  'gets new data and binds it to the datagrid
  BindGrid()

  End Sub

  HELP HELP HELP!!!!

  Best Regards

  Robert Sindall
  ______________________________
  Home: robert@t...
  Hotmail: robert_sindall@h...
  ______________________________
  Tel: +44 (0)1242 518955






  Return to Index