Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 4

For yourfilename.

aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"%> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="scrmgr" runat="server"></asp:ScriptManager> <div id="tabmsg" align="center" runat="server"><asp:Label ID="lblmsg" ForeColor="Blue" runat="server"></asp:Label></div> <div align="right"><a href="addcustomer.aspx">Want to add new record?</a><br /> <br /> Search Customer : <asp:TextBox ID="txtsearch" runat="server" AutoPostBack="true"></asp:TextBox> <asp:AutoCompleteExtender ID="txtautocompletesearch" TargetControlID="txtsearch" runat="server" MinimumPrefixLength="1" ServiceMethod="getnames" ServicePath="helloworld.asmx" ></asp:AutoCompleteExtender> </div> <div align="center"> <strong> <br /> Grid View</strong><br /> &nbsp;<asp:GridView ID="grdcustomer" AutoGenerateColumns="false" Width="100%" runat="server" OnRowCommand="grdcustomer_RowCommand"> <Columns> <asp:TemplateField HeaderText="Customer Name" ItemStyleHorizontalAlign="Center"> <ItemTemplate > <%#Eval("custname") %> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Customer Email Address" ItemStyleHorizontalAlign="Center"> <ItemTemplate> <%#Eval("custemailaddress") %> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Customer Contact No" ItemStyleHorizontalAlign="Center"> <ItemTemplate> <%#Eval("custcontactno") %> </ItemTemplate> </asp:TemplateField> <asp:TemplateField ItemStyle-HorizontalAlign="Center"> <ItemTemplate> <a href="addcustomer.aspx?id=<%#Eval("id") %>">Edit</a> </ItemTemplate> </asp:TemplateField> <asp:TemplateField ItemStyle-HorizontalAlign="Center"> <ItemTemplate> <asp:HiddenField ID="hfid" runat="server" Value='< %#Eval("id") %>' /> <asp:LinkButton ID="LinkButton0" Text="Delete" CommandName="Deleterecord" CommandArgument='<%#Eval("id") %>' runat="server"></asp:LinkButton> </ItemTemplate> </asp:TemplateField>

</Columns> </asp:GridView> <br /><br /><br /> <strong> Repeater</strong> <br /><br /> <div> <asp:Repeater ID="repcustomer" runat="server" OnItemCommand="repcustomer_ItemCommand"> <HeaderTemplate> <div style="width:100%;"> <div style="float:left;width:30%;border:solid 1px;"><strong>Customer Name</strong></div> <div style="float:left;width:30%;border:solid 1px;"><strong>Customer Email Address</strong></div> <div style="float:left;width:29%;border:solid 1px;"><strong>Customer Contact No</strong></div> <div style="float:left;width:5%;border:solid 1px;"></div> <div style="float:left;width:5%;border:solid 1px;"></div> </div> <div style="clear:both;"> </div> </HeaderTemplate> <ItemTemplate> <div style="width:100%;"> <div style="float:left;width:30%;border:solid 1px;">< %#Eval("custname") %></div> <div style="float:left;width:30%;border:solid 1px;">< %#Eval("custemailaddress") %></div> <div style="float:left;width:29%;border:solid 1px;">< %#Eval("custcontactno") %></div> <div style="float:left;width:5%;border:solid 1px;"> <a href="addcustomer.aspx?id=<%#Eval("id") %>">Edit</a> </div> <div style="float:left;width:5%;border:solid 1px;"> <asp:HiddenField ID="hfid" runat="server" Value='<%#Eval("id") %>' /> <asp:LinkButton ID="LinkButton1" Text="Delete" CommandName="Deleterecord" CommandArgument='<%#Eval("id") %>' runat="server"></asp:LinkButton> </div> </div> <div style="clear:both;"> </div> </ItemTemplate> </asp:Repeater> </div> <br /><br /><br /> <strong>Datalist</strong><br /><br /> <div> <asp:Datalist ID="dlcustomer" runat="server" Width="100%" ItemStyleHorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" OnItemCommand="dlcustomer_ItemCommand"> <HeaderTemplate> <div style="width:100%;"> <div style="float:left;width:30%;border:solid 1px;"><strong>Customer Name</strong></div> <div style="float:left;width:30%;border:solid 1px;"><strong>Customer Email Address</strong></div> <div style="float:left;width:29%;border:solid 1px;"><strong>Customer Contact No</strong></div> <div style="float:left;width:5%;border:solid 1px;"></div> <div style="float:left;width:5%;border:solid 1px;"></div> </div> </div> <div style="clear:both;"> </div>

</HeaderTemplate> <ItemTemplate> <div style="width:100%;"> <div style="float:left;width:30%;border:solid 1px;">< %#Eval("custname") %></div> <div style="float:left;width:30%;border:solid 1px;">< %#Eval("custemailaddress") %></div> <div style="float:left;width:29%;border:solid 1px;">< %#Eval("custcontactno") %></div> <div style="float:left;width:5%;border:solid 1px;"> <a href="addcustomer.aspx?id=<%#Eval("id") %>">Edit</a> </div> <div style="float:left;width:5%;border:solid 1px;"> <asp:HiddenField ID="hfid" runat="server" Value='<%#Eval("id") %>' /> <asp:LinkButton ID="LinkButton2" Text="Delete" CommandName="Deleterecord" CommandArgument='<%#Eval("id") %>' runat="server"></asp:LinkButton></div> </div> </div> <div style="clear:both;"> </div> </ItemTemplate> </asp:Datalist> </div> </div> </form> </body> </html>

For your webservice code file : webservicefilename.cs (here its helloworld.cs)


using using using using using using using using System; System.Collections.Generic; System.Linq; System.Web; System.Web.Services; System.Data.SqlClient; System.Data; System.Configuration;

/// <summary> /// Summary description for helloworld /// </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 helloworld : System.Web.Services.WebService { public helloworld () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public string[] getnames(string prefixText) { SqlConnection conn = new SqlConnection(); SqlCommand cmd = new SqlCommand(); conn.ConnectionString = ConfigurationManager.ConnectionStrings["connection"].ConnectionString; cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "ps_getcustomer"; cmd.Parameters.Add("@searchkeyword", SqlDbType.VarChar, 50).Value = prefixText; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); conn.Open(); da.Fill(dt); conn.Close(); List<string> results = new List<string>(); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { results.Add(dr["custname"].ToString()); } } return results.ToArray(); } }

You might also like