|
 |
aspx_mobile thread: How to update an ObjectList.HELP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Message #1 by "koko" <unmask5@h...> on Fri, 16 Aug 2002 08:56:12
|
|
Hi,koko here.Stuck in my project and need help.Don;t know how to update
objectlist.This is getting serious.
My project is using Visual Studio.Net and VB as it language,and disply in
Pocket PC.
The objectlist page consist of 3 columns Roomkey,Status and Borrower.
I manage to connect to a database and had my dataset ready.It show all the
stuff but my purpose is that when i click on the Roomkey num the program
must be able to show Status and the Borrower in their desired Textbox in
the nexr form which is form2.Which means at the objectlist i can see the 3
colums Roomkey,status and Borrower but only Roomkey can be click,and when
i click on it,it bring me to the next form and show me the Status and the
Borrower in the textbox(that means the Status in the status textbox and
the borrower in the borrower textbox),the form2 page is the form where i
do my update.Below is my coding,please point out any error or mistake i
had made.
Code Behind:
Imports System.Data
Imports System.Data.OleDb
Imports System.Web.Security
Imports System.Web.Mobile
Imports System.Web.UI.Control
Imports System.Web.UI.MobileControls
Imports System.Web.Mobile.MobileFormsAuthentication
Public Class KS
Inherits System.Web.UI.MobileControls.MobilePage
Protected WithEvents Logged As System.Web.UI.MobileControls.Form
Protected WithEvents msg2 As System.Web.UI.MobileControls.Label
Protected WithEvents objlst As System.Web.UI.MobileControls.ObjectList
Protected WithEvents Lnk As System.Web.UI.MobileControls.Link
Protected WithEvents Lnk1 As System.Web.UI.MobileControls.Link
Protected WithEvents Lbl1 As System.Web.UI.MobileControls.Label
Protected WithEvents msg3 As System.Web.UI.MobileControls.Label
Protected WithEvents TB2 As System.Web.UI.MobileControls.TextBox
Protected WithEvents Cmd1 As System.Web.UI.MobileControls.Command
Protected WithEvents Cmd2 As System.Web.UI.MobileControls.Command
Protected WithEvents Borrower As System.Web.UI.MobileControls.Label
Protected WithEvents Status As System.Web.UI.MobileControls.Label
Protected WithEvents cmdCancel As System.Web.UI.MobileControls.Command
Protected WithEvents LblDisplay As System.Web.UI.MobileControls.Label
Protected WithEvents cmdUpdate As System.Web.UI.MobileControls.Command
Protected WithEvents tbstatus As System.Web.UI.MobileControls.TextBox
Protected WithEvents tbBorrower As System.Web.UI.MobileControls.TextBox
Protected WithEvents Form2 As System.Web.UI.MobileControls.Form
Protected WithEvents Lblprompt As System.Web.UI.MobileControls.Label
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Public strCon As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and
Settings\Administrator\Desktop\ch12\pda_database.mdb"
Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Handles MyBase.Load
If IsPostBack = False Then
BindList()
End If
End Sub
Public Sub BindList()
'Define the ADO.NET objects for selecting Roomkeynum.
Dim strSQL As String = "SELECT * FROM Roomkeynum WHERE ID"
'Create a Connection object and pass the connection string to it.
Dim Con As New OleDbConnection(strCon)
'Instantiate an OleDbCommand Obj & pass the SQL statement and the
'OleDbConnection Obj to it,b4 opening a database connection by
'calling the Open() method of the OleDbConnection obj.
Dim cmd As New OleDbCommand(strSQL, Con)
Dim DA As New OleDbDataAdapter(cmd)
Dim DS As New DataSet()
DA.Fill(DS, "Roomkeynum")
With objlst
.DataSource = DS
.LabelField = "Roomkey"
.AutoGenerateFields = True
.DataBind()
End With
End Sub
Public Sub Edit_OnItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.MobileControls.ObjectListCommandEventArgs)
Form2.DataBind()
ActiveForm = Form2
If e.CommandName = "Edit" Then
Form2.Visible = True
cmdCancel.Text = "Cancel"
LblDisplay.Text = "Update Status"
End If
End Sub
Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As EventArgs)
UpdateEmployee()
End Sub
Sub cmdCancel_Click(ByVal sender As Object, ByVal e As EventArgs)
ActiveForm = Logged
objlst.ViewMode = ObjectListViewMode.List
DataBind()
End Sub
Public Sub UpdateEmployee()
Dim strCon As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and
Settings\Administrator\Desktop\ch12\pda_database.mdb"
Dim Updatecmd As String = "UPDATE Roomkeynum SET Borrower = ?,
Status= ? WHERE ID = ?"
Dim con As New OleDbConnection(strCon)
Dim cmd As New OleDbCommand(Updatecmd, con)
cmd.Parameters.Add("Borrower", OleDbType.Char, 20).Value =
tbBorrower.Text
cmd.Parameters.Add("@Status", OleDbType.Char, 10).Value =
tbstatus.Text
cmd.Connection.Open()
Try
cmd.ExecuteNonQuery()
LblDisplay.Text = "Info Updated!"
Catch e As OleDbException
LblDisplay.Text = "Update Failed!"
End Try
cmd.Connection.Close()
cmdCancel.Text = "Back"
Form2.Visible = False
End Sub
End Class
[FROM THIS SENTENCE BELOW IS THE INLINE CODE]
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Web.UI.Control" %>
<%@ Import Namespace="System.Data.Oledb" %>
<%@ Import Namespace="System.Web.Security"%>
<%@ Import Namespace="System.Web.Mobile" %>
<%@ Page Language="vb" Debug="true" AutoEventWireup="true"
Codebehind="KS.aspx.vb" Inherits="mwp5.KS" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile, Version=1.0.3300.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" %>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="http://schemas.microsoft.com/Mobile/Page"
name="vs_targetSchema">
<body Xmlns:mobile="http://schemas.microsoft.com/Mobile/WebForm">
<script language="vb" runat="server"></script>
<mobile:form id="Logged" runat="server" PagerStyle-Alignment="Center"
PagerStyle-Wrapping="Wrap" Paginate="true" Wrapping="Wrap">
<mobile:Label id="Lblprompt" runat="server" Alignment="Center"
>Welcome.You have successfully login.Please proceed to key-renting
below.</mobile:Label>
<mobile:ObjectList id="objlst" runat="server"
OnItemCommand="Edit_OnItemCommand" TableFields="Roomkey;Status;Borrower"
CommandStyle-StyleReference="subcommand" LabelStyle-StyleReference="title"
LabelStyle-Font-Name="Arial" LabelStyle-ForeColor="LightGray" LabelStyle-
Font-Size="Normal">
<Command Name="Edit" Text="Edit Details"></Command>
</mobile:ObjectList>
<mobile:Label id="msg2" Font-Name="Century Gothic"
Alignment="Center" Runat="server"></mobile:Label>
<mobile:Link id="Lnk" runat="server" Alignment="Center"
NavigateUrl="UL.aspx">Logout</mobile:Link>
</mobile:form>
<mobile:form id="Form2" runat="server" BackColor="Coral">
<mobile:Label id="LblDisplay" Runat="server"
StyleReference="Title"></mobile:Label>
<mobile:Label id="Borrower" Runat="server">Borrower:</mobile:Label>
<mobile:TextBox id="tbBorrower" runat="server" MaxLength="40">
<%# objlst.Selection("Borrower") %>
</mobile:TextBox>
<mobile:Label id="Status" Runat="server">Status:</mobile:Label>
<mobile:TextBox id="tbstatus" runat="server" MaxLength="2">
<%# objlst.Selection("Status")%>
</mobile:TextBox>
<mobile:Label id="msg3" runat="server" Alignment="Center" ></mobile:Label>
<mobile:Command id="cmdUpdate" onclick="cmdUpdate_Click" runat="server"
BreakAfter="False">Update</mobile:Command>
<mobile:Command id="cmdCancel" onclick="cmdCancel_Click" runat="server"
Font-Bold="True" Alignment="Right" Runat="server">Cancel</mobile:Command>
<mobile:Link id="Lnk1" runat="server"
NavigateUrl="UL.aspx">Logout</mobile:Link>
</mobile:form>
</body>
|
|
 |