<%@ Page Language="VB" AutoEventWireup="true" CodeFile="tel_mail_edit_form.aspx.vb" Inherits="tel_mail_tel_mail_edit_form" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server" language ="VBScript">
Dim objConn As New OleDbConnection
Dim objCmd As New OleDbCommand
Dim dtReader As OleDbDataReader
Dim strConnString,strSQL As String
Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
Me.DropDownList2.SelectedItem.Text = Me.DropDownList2.SelectedItem.Text
End Sub
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Me.HyperLink3.Text = "ค้นหาข้อมูล"
Me.HyperLink4.Text = "เพิ่มข้อมูล"
Me.HyperLink3.NavigateUrl = "./tel_mail_search.aspx"
Me.HyperLink4.NavigateUrl = "./tel_mail_add.aspx"
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("~/aspweb/tel_mail.mdb") & ";Jet OLEDB:Database Password=;"
objConn.ConnectionString = strConnString
objConn.Open()
If Not Page.IsPostBack() Then
ViewData()
End If
End Sub
Sub ViewData()
'*** DataTable ***'
Dim dtAdapter As OleDbDataAdapter
Dim dt As New DataTable
strSQL = "SELECT * FROM tel_mail WHERE tm_id = '" & Request.QueryString("tm_id") & "' "
dtAdapter = New OleDbDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
If dt.Rows.Count > 0 Then
Me.txttm_id.Text = dt.Rows(0)("tm_id")
Me.txttm_prefix.Text = dt.Rows(0)("tm_prefix")
Me.txttm_name.Text = dt.Rows(0)("tm_name")
Me.txttm_surname.Text = dt.Rows(0)("tm_surname")
Me.txttm_tel.Text = dt.Rows(0)("tm_tel")
Me.txttm_mobile.Text = dt.Rows(0)("tm_mobile")
Me.txttm_mail.Text = dt.Rows(0)("tm_mail")
Me.txttm_place.Text = dt.Rows(0)("tm_place")
Me.DropDownList2.SelectedItem.Text = dt.Rows(0)("tm_under")
End If
End Sub
Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs)
strSQL = "UPDATE tel_mail SET " & _
" tm_prefix = '" & Me.txttm_prefix.Text & "' " & _
" ,tm_name = '" & Me.txttm_name.Text & "' " & _
" ,tm_surname = '" & Me.txttm_surname.Text & "' " & _
" ,tm_tel = '" & Me.txttm_tel.Text & "' " & _
" ,tm_mobile = '" & Me.txttm_mobile.Text & "' " & _
" ,tm_mail = '" & Me.txttm_mail.Text & "' " & _
" ,tm_place = '" & Me.txttm_place.Text & "' " & _
" ,tm_under = '" & Me.DropDownList2.SelectedItem.Text & "' " & _
" WHERE tm_id = '" & Request.QueryString("tm_id") & "' "
objCmd = New OleDbCommand
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
Me.pnlAdd.Visible = False
Try
objCmd.ExecuteNonQuery()
Me.lblStatus.Text = "<h5>ระบบได้ทำการแก้ไขข้อมูลเรียบร้อยแล้ว</h5>"
Me.lblStatus.Visible = True
Catch ex As Exception
Me.lblStatus.Text = "ไม่สามารถทำการแก้ไขข้อมูลได้"
End Try
End Sub
Sub Page_UnLoad()
objConn.Close()
objConn = Nothing
End Sub
</script>
<html>
<head>
<link rel="stylesheet" type="text/css" title="CSS" href="Home_files/style1.css" media="screen" style =" background-color:#DAA520 "><link />
<title>Tel || Mail</title>
</head>
<body><center> <style type="text/css">
body {background-color: #FFFACD }
</style>
<!-- Begin Container -->
<div id="container" style ="background-color : #3CB371 ">
<!-- Begin Masthead -->
<div id="masthead" >
<h2> เบอร์โทรศัพท์และ Email ที่เกี่ยวข้องกับ CSSC </h2>
</div>
<!-- End Masthead -->
<br />
<table width="800" border="1" align="center">
<tr>
<td bgcolor="lightgreen" align="center"><a href="tel_mail_show_ces.aspx">บุคลากรของ CSSC</a></td>
<td bgcolor="lightblue" align="center"><a href="tel_mail_show_cssc.aspx">ที่ปรึกษาและสมาชิก CES</td></a>
<td bgcolor="lightgrey" align="center"><a href="tel_mail_show_kmutt.aspx">บุคลากร สรบ. และ มจธ.</a></td>
<td bgcolor="lightskyblue" align="center"><a href="tel_mail_show_other.aspx">หน่วยงานภายนอก</a></td>
<td bgcolor="#EEDD82" align="center"><a href="tel_mail_show.aspx">รายชื่อทั้งหมด</a></td>
</tr>
</table>
<br />
<form id="form1" runat="server">
<asp:Panel id="pnlAdd" runat="server">
<table width="353" border="0">
<tbody>
<tr>
<td width="102">
<asp:Label id="lbltm_id" runat="server" text="ID"></asp:Label></td>
<td width="235">
<asp:TextBox id="txttm_id" runat="server" Width="60px"></asp:TextBox>
</td>
</tr>
<tr>
<td width="102">
<asp:Label id="lbltm_prefix" runat="server" text="คำนำหน้า"></asp:Label></td>
<td width="235">
<asp:TextBox id="txttm_prefix" runat="server" Width="60px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label id="lbltm_name" runat="server" text="ชื่อ"></asp:Label></td>
<td>
<asp:TextBox id="txttm_name" runat="server" Width="177px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label id="lbltm_surname" runat="server" text="นามสกุล"></asp:Label></td>
<td>
<asp:TextBox id="txttm_surname" runat="server" Width="177px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label id="lbltm_tel" runat="server" text="เบอร์โทร"></asp:Label></td>
<td>
<asp:TextBox id="txttm_tel" runat="server" Width="76px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label id="lbltm_mobile" runat="server" text="เบอร์มือถือ"></asp:Label></td>
<td>
<asp:TextBox id="txttm_mobile" runat="server" Width="76px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label id="lbltm_mail" runat="server" text="E-mail"></asp:Label></td>
<td>
<asp:TextBox id="txttm_mail" runat="server" Width="177px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label id="lbltm_place" runat="server" text="สถานที่"></asp:Label></td>
<td>
<asp:TextBox id="txttm_place" runat="server" Width="120px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label id="tm_under" runat="server" text="หน่วยงาน"
style="font-weight: 700"></asp:Label>
</td>
<td>
 <asp:DropDownList id="DropDownList2" AutoPostBack="True" runat="server">
<asp:ListItem>CSSC</asp:ListItem>
<asp:ListItem>CES</asp:ListItem>
<asp:ListItem>KMUTT</asp:ListItem>
<asp:ListItem>OTHER</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<br />
<asp:Button id="btnSave" onclick="btnSave_Click" runat="server" Text="แก้ไขข้อมูล"></asp:Button>
<br />
</asp:Panel>
<asp:Label id="lblStatus" runat="server" visible="True"></asp:Label>
<table> <br />
<asp:HyperLink id="HyperLink3" runat="server">HyperLink</asp:HyperLink><br />
<asp:HyperLink id="HyperLink4" runat="server">HyperLink</asp:HyperLink>
</table>
</form></div>
</body>
</html>
หน้าแสดงข้อมูล
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="tel_mail_show_cssc.aspx.vb" Inherits="tel_mail_tel_mail_show_cssc" %>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<script runat="server" language ="vbscript">
Dim objConn As OleDbConnection
Dim objCmd As OleDbCommand
Dim strSQL As String
Dim dtReader As OleDbDataReader
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Me.HyperLink3.Text = "ค้นหาข้อมูล"
Me.HyperLink4.Text = "เพิ่มข้อมูล"
Me.HyperLink3.NavigateUrl = "./tel_mail_search.aspx"
Me.HyperLink4.NavigateUrl = "./tel_mail_add.aspx"
Dim strConnString As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("~/aspweb/tel_mail.mdb") & ";Jet OLEDB:Database Password=;"
objConn = New OleDbConnection(strConnString)
objConn.Open()
If Not Page.IsPostBack() Then
BindData()
End If
End Sub
Sub BindData()
Dim strSQL As String
strSQL = "SELECT * FROM tel_mail where tm_under = 'cssc' "
Dim dtReader As OleDbDataReader
objCmd = New OleDbCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
'*** BindData to Repeater ***'
myRepeater.DataSource = dtReader
myRepeater.DataBind()
dtReader.Close()
dtReader = Nothing
End Sub
Sub Page_UnLoad()
objConn.Close()
objConn = Nothing
End Sub
Sub myRepeater_ItemCommand(ByVal source As Object, ByVal e As RepeaterCommandEventArgs) Handles myRepeater.ItemCommand
If e.CommandName = "Delete" Then
Dim lbltm_name As Label = CType(e.Item.FindControl("lbltm_name"), Label)
strSQL = "DELETE FROM tel_mail WHERE tm_name = '" & lbltm_name.Text & "' "
objCmd = New OleDbCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
BindData()
End If
End Sub
Sub myRepeater_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles myRepeater.ItemDataBound
'*** ID ***'
'Dim lbltm_id As Label = CType(e.Item.FindControl("lbltm_id"), Label)
'If Not IsNothing(lbltm_id) Then
'lbltm_id.Text = e.Item.DataItem("tm_id")
' End If
'*** prefix ***'
Dim lbltm_prefix As Label = CType(e.Item.FindControl("lbltm_prefix"), Label)
If Not IsNothing(lbltm_prefix) Then
lbltm_prefix.Text = e.Item.DataItem("tm_prefix")
End If
'*** name ***'
Dim lbltm_name As Label = CType(e.Item.FindControl("lbltm_name"), Label)
If Not IsNothing(lbltm_name) Then
lbltm_name.Text = e.Item.DataItem("tm_name")
End If
'*** surname ***'
Dim lbltm_surname As Label = CType(e.Item.FindControl("lbltm_surname"), Label)
If Not IsNothing(lbltm_surname) Then
lbltm_surname.Text = e.Item.DataItem("tm_surname")
End If
'*** tel ***'
Dim lbltm_tel As Label = CType(e.Item.FindControl("lbltm_tel"), Label)
If Not IsNothing(lbltm_tel) Then
lbltm_tel.Text = e.Item.DataItem("tm_tel")
End If
'*** mobile ***'
Dim lbltm_mobile As Label = CType(e.Item.FindControl("lbltm_mobile"), Label)
If Not IsNothing(lbltm_mobile) Then
lbltm_mobile.Text = e.Item.DataItem("tm_mobile")
End If
'*** E-mail ***'
Dim lbltm_mail As Label = CType(e.Item.FindControl("lbltm_mail"), Label)
If Not IsNothing(lbltm_mail) Then
lbltm_mail.Text = e.Item.DataItem("tm_mail")
End If
'*** place ***'
Dim lbltm_place As Label = CType(e.Item.FindControl("lbltm_place"), Label)
If Not IsNothing(lbltm_place) Then
lbltm_place.Text = e.Item.DataItem("tm_place")
End If
'*** under ***'
Dim lbltm_under As Label = CType(e.Item.FindControl("lbltm_under"), Label)
If Not IsNothing(lbltm_under) Then
lbltm_under.Text = e.Item.DataItem("tm_under")
End If
'*** Hyperlink ***'
Dim hplEdit As HyperLink = CType(e.Item.FindControl("hplEdit"), HyperLink)
If Not IsNothing(hplEdit) Then
hplEdit.Text = "Edit"
hplEdit.NavigateUrl = "tel_mail_edit_form.aspx?tm_id=" & e.Item.DataItem("tm_id")
End If
Dim lnkDelete As LinkButton = CType(e.Item.FindControl("lnkDelete"), LinkButton)
If Not IsNothing(lnkDelete) Then
lnkDelete.Attributes.Add("OnClick", "return confirm('Delete Record?');")
End If
End Sub
</script>
<html>
<head>
<title>Tel || Mail</title>
<link rel="stylesheet" type="text/css" title="CSS" href="Home_files/style1.css" media="screen"><link />
</head>
<body>
<center> <style type="text/css">
body {background-color: #FFFACD }
</style>
<!-- Begin Container -->
<div id="container" style ="background-color : #3CB371 ">
<!-- Begin Masthead -->
<div id="masthead" >
<h2> เบอร์โทรศัพท์และ Email ที่เกี่ยวข้องกับ CSSC </h2>
</div>
<!-- End Masthead -->
<br />
<table width="800" border="1" align="center">
<tr>
<td bgcolor="lightgreen" align="center"><a href="#cssc">บุคลากรของ CSSC</a></td>
<td bgcolor="lightblue" align="center"><a href="tel_mail_show_ces.aspx">ที่ปรึกษาและสมาชิก CES</td></a>
<td bgcolor="lightgrey" align="center"><a href="tel_mail_show_kmutt.aspx">บุคลากร สรบ. และ มจธ.</a></td>
<td bgcolor="lightskyblue" align="center"><a href="tel_mail_show_other.aspx">หน่วยงานภายนอก</a></td>
<td bgcolor="#EEDD82" align="center"><a href="tel_mail_show.aspx">รายชื่อทั้งหมด</a></td>
</tr>
</table>
<br />
<form id="form1" runat="server">
<asp:Repeater id="myRepeater" runat="server">
<HeaderTemplate>
<table width="100%" border="1">
<tr>
<!--<th>ID</th>-->
<th>คำนำหน้า</th>
<th>ชื่อ</th>
<th>นามสกุล</th>
<th>เบอร์โทร</th>
<th>เบอร์มือถือ</th>
<th>E-mail</th>
<th>สถานที่</th>
<th>หน่วยงาน</th>
<th>แก้ไข</th>
<th>ลบ</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center" width = "100px"><asp:Label id="lbltm_prefix" runat="server"></asp:Label></td>
<td width = "120px"><asp:Label id="lbltm_name" runat="server"></asp:Label></td>
<td width = "120px"><asp:Label id="lbltm_surname" runat="server"></asp:Label></td>
<td align="center" width = "100px"><asp:Label id="lbltm_tel" runat="server"></asp:Label></td>
<td align="center" width = "100px"><asp:Label id="lbltm_mobile" runat="server"></asp:Label></td>
<td align="center" width = "250px"><asp:Label id="lbltm_mail" runat="server"></asp:Label></td>
<td align="center" width = "200px"><asp:Label id="lbltm_place" runat="server"></asp:Label></td>
<td align="center" width = "80px"><asp:Label id="lbltm_under" runat="server"></asp:Label></td>
<td align="center" width = "80px"><asp:Hyperlink id="hplEdit" runat="server"></asp:Hyperlink></td>
<td align="center" width = "80px"><asp:LinkButton id="lnkDelete" CommandName="Delete" runat="server">Delete</asp:LinkButton></td>
</tr>
</ItemTemplate>
</asp:Repeater>
<table> <br />
<asp:HyperLink id="HyperLink3" runat="server">HyperLink</asp:HyperLink><br />
<asp:HyperLink id="HyperLink4" runat="server">HyperLink</asp:HyperLink>
</table>
</form></div>
</body>
</html>
Tag : .NET, Ms Access, VBScript, Web (ASP.NET), VS 2008 (.NET 3.x)