 |
|
|
 |
 |
|

ขอบคุณคะ...ได้นำเอาCodeไปใช้แล้วยังerror อยู่คะ
รบกวนด้วยนะคะ....ขอบคุณมากๆๆคะ
|
 |
 |
 |
 |
Date :
2012-07-18 19:25:40 |
By :
janjira0019 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คะ...ติดปัญหาอยู่ว่าใช้งานไม่เป็นคะมือใหม่หัดเขียน
รบกวนช่วยนะแนะด้วยนะคะ..ขอบคุนคะ
|
 |
 |
 |
 |
Date :
2012-07-18 22:57:58 |
By :
janjira0019 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดูตามนั้นครับ
|
 |
 |
 |
 |
Date :
2012-07-19 06:17:34 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หน้าหลักที่ต้องการใช้ Aoutcomplete
Code (ASP)
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="Autoname" runat="server"
EnableCaching="true"
BehaviorID="AutoCompleteEx"
MinimumPrefixLength="2"
TargetControlID="txtname"
ServicePath="AutoExtender.asmx"
ServiceMethod="Getname"
CompletionInterval="500"
CompletionSetCount="10"
CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true"
>
</asp:AutoCompleteExtender>
หน้าต่างwebService
Code (ASP)
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System
Imports System.Collections
Imports System.Linq
Imports System.Web
Imports System.Xml.Linq
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class AutoExtender
Inherits System.Web.Services.WebService
Dim cn As New SqlClient.SqlConnection()
Dim ds As New DataSet
Dim dt As New DataTable
Dim strCn As String
<WebMethod()> _
Public Function Getname(ByVal prefixText As String, ByVal count As Integer) As String()
'ADO.Net
strCn = "Server=localhost;UID=sa;PASSWORD=admin;database=Refer;Max Pool Size=400;Connect Timeout=600;"
cn.ConnectionString = strCn
Dim cmd As New SqlClient.SqlCommand
cmd.Connection = cn
cmd.CommandType = CommandType.Text
'Compare String From Textbox(prefixText)
'AND String From Column in DataBase(CompanyName)
'If String from DataBase is equal to String from TextBox(prefixText)
'then add it to return ItemList
'-----I defined a parameter instead of passing value
'directly to prevent SQL injection--------'
cmd.CommandText = "SELECT code,codename from icd10 Where codename like @myParameter"
cmd.Parameters.AddWithValue("@myParameter", "%" + prefixText + "%")
Try
cn.Open()
cmd.ExecuteNonQuery()
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds)
Catch ex As Exception
Finally
cn.Close()
End Try
dt = ds.Tables(0)
'Then return List of string(txtItems) as result
Dim txtname As New List(Of String)
Dim dbValues As String
For Each row As DataRow In dt.Rows
''String From DataBase(dbValues)
dbValues = row("codename").ToString()
dbValues = dbValues.ToLower()
txtname.Add(dbValues)
Next
Return txtname.ToArray()
End Function
End Class
ของtest webService ดึงข้อมูลมาแต่ถ้าrunในหน้าหลักไม่ดึงข้อมููลมา
รบกวนช่วยด้วยให้หน่อยนะคะ
|
 |
 |
 |
 |
Date :
2012-07-20 12:16:08 |
By :
janjira0019 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต้องแยกทดสอบทีละส่วน แล้วดูว่า error ตรงไหน
ลอง test web service ก่อนเลย
ลองรัน .asmx ดูว่าทำงานไหม
|
 |
 |
 |
 |
Date :
2012-07-20 13:13:30 |
By :
อิอิ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณ Guest
ลอง Test ใน web service แล้วดึงข้อมูลมาได้คะ
แต่ถ้ารันในหน้าหลักคีย์ข้อมูลแล้วไม่ขึ้นข้อมูลที่ดึงมาจาก Database เลยคะ
|
 |
 |
 |
 |
Date :
2012-07-20 20:04:04 |
By :
janjira0019 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
test web service แล้วได้ข้อมูลตามรูปที่แนบมาคะ



test ในส่วนของหน้าหลักที่ต้องการให้แสดงผล

|
 |
 |
 |
 |
Date :
2012-07-20 20:14:03 |
By :
janjira0019 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
test web service แล้วได้ข้อมูลตามรูปที่แนบมาคะ

|
 |
 |
 |
 |
Date :
2012-07-20 20:16:02 |
By :
janjira0019 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาไว้เป็นตัวอย่างนะ ผมว่าคุณขาดไปตัวนึงนะ
Code (C#)
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/StaffAutoComplete.asmx" />
</Services>
</ajaxToolkit:ToolkitScriptManager>
ตามนี้
StaffAutoComplete.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
/// <summary>
/// Summary description for StaffAutoComplete
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class StaffAutoComplete : System.Web.Services.WebService
{
public StaffAutoComplete ()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string[] GetCompletionList(string prefixText, int count)
{
Intranet2012DataContext intranet2012 = new Intranet2012DataContext();
//left join
string[] staff = (from s in intranet2012.Staff
join u in intranet2012.UserTable on s.ID equals u.StaffID into JoinedStaffUser
from u in JoinedStaffUser.DefaultIfEmpty()
where (s.Name.Trim() + " " + s.LastName.Trim()).StartsWith(prefixText) && u.StaffID == null
orderby s.Name
select new
{
StaffName = string.Format("{0} {1}", s.Name.Trim(), s.LastName.Trim())
}).Select(st => st.StaffName).Take(count).ToArray();
return staff;
}
}
Site.master
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<link href="Styles/AutoComplete.css" rel="stylesheet" type="text/css" />
<link href="Styles/TabContainer.css" rel="stylesheet" type="text/css" />
<script src="../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form runat="server">
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/StaffAutoComplete.asmx" />
</Services>
</ajaxToolkit:ToolkitScriptManager>
<div class="page">
<div class="header">
<div class="title">
<h1>
Intranet Administrator
</h1>
</div>
<div class="loginDisplay">
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
<AnonymousTemplate>
[ <a href="~/Account/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ]
</AnonymousTemplate>
<LoggedInTemplate>
Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
[ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/" OnLoggedOut="HeadLoginStatus_LoggedOut" /> ]
</LoggedInTemplate>
</asp:LoginView>
</div>
<div class="clear hideSkiplink">
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
<asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
</Items>
</asp:Menu>
</div>
</div>
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</div>
<div class="clear">
</div>
</div>
<div class="footer">
ความลับ
</div>
</form>
</body>
</html>
Register.aspx
<%@ Page Title="Register" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Register.aspx.cs" Inherits="Account_Register" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:CreateUserWizard ID="RegisterUser" runat="server" AutoGeneratePassword="true" RequireEmail="false" EnableViewState="false" OnCreatedUser="RegisterUser_CreatedUser">
<LayoutTemplate>
<asp:PlaceHolder ID="wizardStepPlaceholder" runat="server"></asp:PlaceHolder>
<asp:PlaceHolder ID="navigationPlaceholder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<WizardSteps>
<asp:CreateUserWizardStep ID="RegisterUserWizardStep" runat="server">
<ContentTemplate>
<h2>
Create a New Account
</h2>
<p>
Use the form below to create a new account.
</p>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TextBoxStaff" />
</Triggers>
<ContentTemplate>
<span class="failureNotification">
<asp:Literal ID="ErrorMessage" runat="server"></asp:Literal>
</span>
<asp:ValidationSummary ID="RegisterUserValidationSummary" runat="server" CssClass="failureNotification"
ValidationGroup="RegisterUserValidationGroup"/>
<div class="reg">
<fieldset class="register">
<legend>Account Information</legend>
<p>
<asp:Label ID="StaffLabel" runat="server" AssociatedControlID="TextBoxStaff">Staff Name:</asp:Label>
<asp:TextBox ID="TextBoxStaff" runat="server" CssClass="textEntry" autocomplete="off"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="TextBoxStaff_AutoCompleteExtender" runat="server"
TargetControlID="TextBoxStaff"
ServicePath="~/StaffAutoComplete.asmx"
ServiceMethod="GetCompletionList"
CompletionInterval="100"
CompletionSetCount="12"
DelimiterCharacters=""
Enabled="true"
EnableCaching="true"
MinimumPrefixLength="1"
CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem">
</ajaxToolkit:AutoCompleteExtender>
<asp:Image ID="ImageCheck" ImageUrl="~/images/true.png" ImageAlign="AbsMiddle" Visible="false" runat="server" />
<asp:RequiredFieldValidator ID="SatffRequired" runat="server" ControlToValidate="TextBoxStaff"
CssClass="failureNotification" ErrorMessage="Staff name is required." ToolTip="Staff name is required."
ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
<asp:TextBox ID="UserName" runat="server" CssClass="textEntry" ReadOnly="true" Enabled="false"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
CssClass="failureNotification" ErrorMessage="User Name is required." ToolTip="User Name is required."
ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<div style="width: 100%; height: 320px;">
</div>
</fieldset>
<p class="submitButton">
<asp:Button ID="CreateUserButton" runat="server" CommandName="MoveNext" Text="Create User" Enabled="false"
ValidationGroup="RegisterUserValidationGroup"/>
</p>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
<CustomNavigationTemplate>
</CustomNavigationTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep runat="server"></asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
</asp:Content>
|
 |
 |
 |
 |
Date :
2012-07-23 14:43:30 |
By :
อิอิ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เจอแระว่าผิดตรงไหน
Code (VB.NET)
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class AutoExtender
Inherits System.Web.Services.WebService
Dim cn As New SqlClient.SqlConnection()
Dim ds As New DataSet
Dim dt As New DataTable
Dim strCn As String
เอา commant ตรง <System.Web.Script.Services.ScriptService()> _ ออกซะ
|
 |
 |
 |
 |
Date :
2012-07-23 14:46:05 |
By :
อิอิ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|