Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class ProductDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] GetCompletionList(string prefixText, int count, string contextKey)
    {
        SqlConnection conn = new SqlConnection("Data Source=LGTUSHI-PC\\SQLTUSHI;AttachDbFilename=D:\\da\\DataDictionary.mdf;Integrated Security=True");
        conn.Open();

        DataSet ds = new DataSet();
        SqlDataAdapter sda = new SqlDataAdapter("select ProductName from ProductDetails", conn);
        sda.Fill(ds, "ProductDetails");
        conn.Close();

        string[] main = new string[0];
        for (int i = 0; i < ds.Tables[0].Rows.Count - 1; i++)
        {
            if (ds.Tables[0].Rows[i].ItemArray[0].ToString().ToLower().StartsWith(prefixText.ToLower()))
            {
                Array.Resize(ref main, main.Length + 1);
                main[main.Length - 1] = ds.Tables[0].Rows[i].ItemArray[0].ToString();
                if (main.Length == 10)
                    break;



            }
        }
        Array.Sort(main);
        return main;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection("Data Source=LGTUSHI-PC\\SQLTUSHI;AttachDbFilename=D:\\da\\DataDictionary.mdf;Integrated Security=True");
        conn.Open();

        string Query = "if not exists(select * from ProductDetails where ProductName ='" + txtProductName.Text.Trim() + "')insert into ProductDetails (ProductName,ModelNumber,CompanyName,Description,Color,Quantity,Price,SaleInPercentage,SalePrice,StandardPrice,PrimePrice,AveragePrice)values('" + txtProductName.Text.Trim() + "','" + txtmodelnumber + "','" +txtCompanyName.Text.Trim() + "','" + txtDescription.Text.Trim() + "','" + txtColor.Text.Trim() + "','" + txtQuantity.Text.Trim() + "','" + txtPrice.Text.Trim() + "','" + txtSaleinPercantage.Text.Trim() + "','" + txtSalePrice.Text.Trim() + "','" + txtStandardPrice.Text.Trim() + "','" + txtPrimePrice.Text.Trim() + "','" + txtAveragePrice.Text.Trim() + "') ";
        SqlCommand cmd = new SqlCommand(Query,conn);
        if (cmd.ExecuteNonQuery() > 0)
        {
            lblMessage.Text = "Data Inserted Successfully";
        }
        else
        {
            lblMessage.Text = "Error ";
        }

        conn.Close();
    }

   

    

}



my aspx page code :

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ProductDetail.aspx.cs" Inherits="ProductDetail" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>


    <style type="text/css">
        .style1
        {
            width: 80%;
        }
        .style2
        {
            height: 20px;
        }
        .form_error

        .style3
        {
            width: 151px;
        }
        .style4
        {
            height: 20px;
            width: 151px;
        }
        .style5
        {
            width: 210px;
        }
        .style6
        {
            height: 20px;
            width: 210px;
        }

    </style>
</head>
<body>
     <script language="javascript" type="text/javascript">

         function sumCalc() {
             var _txtPrice = document.getElementById('<%= txtPrice.ClientID %>');
             var _txtSaleinPercantage = document.getElementById('<%= txtSaleinPercantage.ClientID %>');
             var _txtSalePrice = document.getElementById('<%= txtSalePrice.ClientID %>');
             var t1 = 0, t2 = 0;

             if (_txtPrice != "") t1 = _txtPrice.value;
             if (_txtSaleinPercantage != "") t2 = _txtSaleinPercantage.value;
             var t3 = (parseInt(t2) * parseInt(t1));
             _txtSalePrice.value = (parseInt(t1) + (t3 / 100));
         }


         function colorChanged(sender) {
             sender.get_element().style.color = "#" + sender.get_selectedColor();
         }
    </script>



    <form id="form1" runat="server">
   <asp:ToolkitScriptManager ID="toolkit1" runat="server"></asp:ToolkitScriptManager>
    <table class="style1">
        <tr>
            <td colspan="2">
                <h1>
                    Product Detail</h1>
            </td>
            <td colspan="2" style="text-align: center">
                <asp:Image ID="Image1" runat="server" Height="154px" ImageUrl="~/lg.gif"
                    style="text-align: right" />
            </td>
        </tr>
        <tr>
            <td class="style5">
                &nbsp;</td>
            <td class="style3">
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style5">
                ProductName</td>
            <td class="style3">
                :</td>
            <td>
                <asp:TextBox ID="txtProductName" runat="server" Height="23px" Width="300px"></asp:TextBox>



                <asp:AutoCompleteExtender ID="txtProductName_AutoCompleteExtender"
                    runat="server" CompletionSetCount="1" DelimiterCharacters="" Enabled="True"
                    FirstRowSelected="True" ServiceMethod="GetCompletionList" ServicePath=""
                    TargetControlID="txtProductName" UseContextKey="True">
                </asp:AutoCompleteExtender>



            </td>
            <td>
                <asp:RequiredFieldValidator ID="rfvProductName" runat="server"
                    ControlToValidate="txtProductName" Display="Dynamic"
                    ErrorMessage="Enter ProductName" ForeColor="Red" SetFocusOnError="True"
                    ValidationGroup="Save"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                ModelNumber</td>
            <td class="style3">
                :</td>
            <td>
                <asp:TextBox ID="txtmodelnumber" runat="server" Height="23px" Width="300px"></asp:TextBox>












            </td>
            <td>
                <asp:RequiredFieldValidator ID="rfvmodelnumber" runat="server"
                    ControlToValidate="txtmodelnumber" Display="Dynamic"
                    ErrorMessage="Enter ModelNumber" ForeColor="Red" SetFocusOnError="True"
                    ValidationGroup="Save"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                CompanyName</td>
            <td class="style3">
                :</td>
            <td>
                <asp:TextBox ID="txtCompanyName" runat="server" Height="23px" Width="300px"></asp:TextBox>

            </td>
            <td>
                <asp:RequiredFieldValidator ID="rfvCompanyName" runat="server"
                    ControlToValidate="txtCompanyName" Display="Dynamic"
                    ErrorMessage="Enter CompanyName" ForeColor="Red" ValidationGroup="Save"
                    SetFocusOnError="True"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style6">
                Description</td>
            <td class="style4">
                :</td>
            <td class="style2">
                <asp:TextBox ID="txtDescription" runat="server" Height="23px" Width="300px"></asp:TextBox>
            </td>
            <td class="style2">
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style5">
                Color
            </td>
            <td class="style3">
               :</td>
            <td>
                <asp:TextBox ID="txtColor" runat="server" Height="23px" Width="300px"></asp:TextBox>
                 <asp:ColorPickerExtender runat="server" ID="ColorPickerExtender1" TargetControlID="txtColor" SampleControlID="txtsample"></asp:ColorPickerExtender>
                <asp:TextBox ID="txtsample" runat="server" Width="30px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="rfvColor" runat="server"
                    ControlToValidate="txtColor" Display="Dynamic" ErrorMessage="Enter Color"
                    ForeColor="Red" ValidationGroup="Save" SetFocusOnError="True"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                Quantity</td>
            <td class="style3">
               :</td>
            <td>
                <asp:TextBox ID="txtQuantity" runat="server" Height="23px" Width="300px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="rfvQuantity" runat="server"
                    ControlToValidate="txtQuantity" Display="Dynamic" ErrorMessage="Enetr Quantity"
                    ForeColor="Red" SetFocusOnError="True" ValidationGroup="Save"></asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="refQuantity" runat="server"
                    ControlToValidate="txtQuantity" Display="Dynamic" ErrorMessage="Enter In Digit"
                    ForeColor="Red" SetFocusOnError="True" ValidationExpression="^\d+$"
                    ValidationGroup="Save"></asp:RegularExpressionValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                Price</td>
            <td class="style3">
               :</td>
            <td>
                <asp:TextBox ID="txtPrice" runat="server" Height="23px" Width="300px" onkeypress="sumCalc();"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="rfvPrice" runat="server"
                    ControlToValidate="txtPrice" ErrorMessage="Enter Price" ForeColor="Red"
                    SetFocusOnError="True" ValidationGroup="Save"></asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="refPrice" runat="server"
                    ControlToValidate="txtPrice" Display="Dynamic" ErrorMessage="Enter In Digit"
                    ForeColor="Red" SetFocusOnError="True" ValidationExpression="^\d+$"
                    ValidationGroup="Save"></asp:RegularExpressionValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                SaleInPercantage</td>
            <td class="style3">
               :</td>
            <td>
                <asp:TextBox ID="txtSaleinPercantage" runat="server" Height="23px"
                    Width="300px" onkeypress="sumCalc();"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="rfvSaleinpercentage" runat="server"
                    ControlToValidate="txtSaleinPercantage" Display="Dynamic"
                    ErrorMessage="Enter SaleInPercentage" ForeColor="Red"
                    ValidationGroup="Save" SetFocusOnError="True"></asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="revsaleinpercentage" runat="server"
                    ControlToValidate="txtSaleinPercantage" Display="Dynamic"
                    ErrorMessage="Enter digit" ForeColor="Red" ValidationExpression="^\d+$"
                    ValidationGroup="Save"></asp:RegularExpressionValidator>
                <asp:RangeValidator ID="rvsaleinpercentage" runat="server"
                    ControlToValidate="txtSaleinPercantage" Display="Dynamic"
                    ErrorMessage="Enter percentage between 0 to 100" ForeColor="Red"
                    MaximumValue="100" MinimumValue="0" SetFocusOnError="True" Type="Integer"
                    ValidationGroup="Save"></asp:RangeValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                SalePrice</td>
            <td class="style3">
               :</td>
            <td>
                <asp:TextBox ID="txtSalePrice" runat="server" Height="23px" Width="300px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="rfvSalePrice" runat="server"
                    ControlToValidate="txtSalePrice" Display="Dynamic"
                    ErrorMessage="Enter SalePrice" ForeColor="Red" SetFocusOnError="True"
                    ValidationGroup="Save"></asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="refSalePrice" runat="server"
                    ControlToValidate="txtSalePrice" Display="Dynamic"
                    ErrorMessage="Enter In Digit" ForeColor="Red" SetFocusOnError="True"
                    ValidationExpression="^\d+$" ValidationGroup="Save"></asp:RegularExpressionValidator>
            </td>
        </tr>
        <tr>
            <td class="style6">
                PrimePrice</td>
            <td class="style4">
                :</td>
            <td class="style2">
                <asp:TextBox ID="txtPrimePrice" runat="server" Height="23px" Width="300px"></asp:TextBox>
            </td>
            <td class="style2">
                <asp:RegularExpressionValidator ID="refPrimeprice" runat="server"
                    ControlToValidate="txtPrimePrice" Display="Dynamic"
                    ErrorMessage="Enter In Digit" ForeColor="Red" SetFocusOnError="True"
                    ValidationExpression="^\d+$" ValidationGroup="Save"></asp:RegularExpressionValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                SatndardPrice</td>
            <td class="style3">
               :</td>
            <td>
                <asp:TextBox ID="txtStandardPrice" runat="server" Height="23px" Width="300px"></asp:TextBox>
            </td>
            <td>
                <asp:RegularExpressionValidator ID="refStandardPrice" runat="server"
                    ControlToValidate="txtStandardPrice" Display="Dynamic"
                    ErrorMessage="Enter In Digit" ForeColor="Red" SetFocusOnError="True"
                    ValidationExpression="^\d+$" ValidationGroup="Save"></asp:RegularExpressionValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                AveragePrice</td>
            <td class="style3">
                :</td>
            <td>
                <asp:TextBox ID="txtAveragePrice" runat="server" Height="23px" Width="300px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="rfvAveragePrice" runat="server"
                    ControlToValidate="txtAveragePrice" Display="Dynamic"
                    ErrorMessage="Enter AveragePrice" ForeColor="Red" SetFocusOnError="True"
                    ValidationGroup="Save"></asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="refAveragePrice" runat="server"
                    ControlToValidate="txtAveragePrice" Display="Dynamic"
                    ErrorMessage="Enter In Digit" ForeColor="Red" SetFocusOnError="True"
                    ValidationExpression="^\d+$" ValidationGroup="Save"></asp:RegularExpressionValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                &nbsp;</td>
            <td class="style3">
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style5">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Button ID="btnupdate" runat="server" Text="Update" Height="26px"
                    Width="65px" />
&nbsp;</td>
            <td class="style3">
                &nbsp;</td>
            <td>
                <asp:Button ID="btnSave" runat="server" Text="Save" Height="26px"
                    onclick="btnSave_Click" ValidationGroup="Save" Width="65px" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Button ID="btnCancel" runat="server" Height="26px" Text="Cancel"
                    Width="65px" />
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style5">
                &nbsp;</td>
            <td class="style3">
                &nbsp;</td>
            <td>
                <asp:Label ID="lblMessage" runat="server"></asp:Label>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style5">
                &nbsp;</td>
            <td class="style3">
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
    <div>

    </div>
    </form>
</body>
</html>
Posted
Updated 15-Sep-13 20:09pm
v2
Comments
Dholakiya Ankit 16-Sep-13 2:10am    
so what's the problem?

Code posted seems to be OK apart from whether the completionlist query has indeed items in it to show.

You can try checking the below options too.

By default, the AutoCompleteExtender wont display suggestions till you type atleast 3 chars. This default behavior by modifying the AutoCompleteExtender MinimumPrefixLength property.

Also, you may increase the value set to the CompletionSetCount property if need more suggestions to be shown.
 
Share this answer
 
you need to check for the property of the textbox. There we can find its solution.
 
Share this answer
 
check it servicepath in autocomplete extender
HTML
ServicePath="~/AutoComplete.asmx"
 
Share this answer
 
Add references of AjaxToolKit.dll in your Bin folder then it will work properly
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900