Wednesday, 26 June 2013

dropdownlist comboBox with database fill using asp.net Ajax

dropdownlist comboBox  with database fill using asp.net Ajax :

aspx :

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="jQuery.aspx.cs"
                  Inherits="jQuery"    %>
 <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   
                        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  
  // AjaxControlToolKit ADD Refrences :

   <%@ Register TagPrefix="ajax" Namespace="AjaxControlToolkit"  
                      Assembly="AjaxControlToolkit" %>

    <html xmlns="http://www.w3.org/1999/xhtml">
       <head runat="server">
       </head>
    <body>
    <form id="form1" runat="server">
       <div>
  // AjaxControlToolKit Use ScriptManager Add

        <ajax:ToolkitScriptManager runat="server">
        </ajax:ToolkitScriptManager>

              Select Name :
 // Ajax COmbo Box
        <ajax:ComboBox ID="ajaxCmbName" runat="server"  
                  AutoPostBack="True" 
                  DropDownStyle="Simple"
                  AutoCompleteMode="SuggestAppend"
                 CaseSensitive="True" 
               ItemInsertLocation="OrdinalValue" >
      </ajax:ComboBox>
 </div>
    </form>
</body>
</html>



aspx  CS:

    SqlConnection Conn = new  
                     SqlConnection(ConfigurationManager.AppSettings["connections"].ToString());
    SqlDataAdapter da = new SqlDataAdapter();

    DataSet ds = new DataSet();

  // Load 

  protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            drpName();
        }

    }

public void drpName()
    {
        Select = "Select * From Register where Name!='' OR Name!=Null Order  
                 By Name ASC";
        da = new SqlDataAdapter(Select,Conn);
        da.Fill(ds);

        ajaxCmbName.DataSource = ds;     // ajax comboBox ID

        ajaxCmbName.DataTextField = "Name";    // Name DataFieldName

        ajaxCmbName.DataBind();
       
}





 // Data Base



No comments:

Post a Comment