using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Collections.Generic; using System.Web.UI.HtmlControls; using System.Text.RegularExpressions; public partial class MultipleColumns : System.Web.UI.Page { #region Session Variables private DataTable _dtProducts { get { return (DataTable)Session["_dtProducts"]; } set { Session["_dtProducts"] = value; } } #endregion protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { D_ddlanimal.Items.Insert(0, "--Select--"); D_ddlanimal.SelectedIndex = 0; FillDataTable(); } } protected void ClientMessaging(string msg) { String script = String.Format("alert('{0}');", msg); Anthem.Manager.IncludePageScripts = true; Page.ClientScript.RegisterStartupScript(this.GetType(), "errMsg", script, true); } protected override void OnInit(EventArgs e) { base.OnInit(e); this.asbProduct.TextChanged += new Anthem.AutoSuggestBox.TextChangedEventHandler(asbProduct_TextChanged); } #region FillDataTable /// <summary> /// This method fills the datatable that is used in this example /// On a real world application you usually would use a database /// </summary> private DataRow FillDataTable() { using (SqlConnection obj_SqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Con"].ConnectionString)) { using (SqlCommand obj_Sqlcommand = new SqlCommand()) { obj_Sqlcommand.CommandType = CommandType.StoredProcedure; obj_Sqlcommand.CommandText = "LRS_SP_CBFM_Sel"; obj_Sqlcommand.Connection = obj_SqlConnection; obj_SqlConnection.Open(); SqlDataAdapter da = new SqlDataAdapter(obj_Sqlcommand); DataSet ds = new DataSet(); da.Fill(ds); ds.WriteXml(Server.MapPath("~/App_Data/Animalcode.xml")); ds.ReadXml(Server.MapPath("~/App_Data/Animalcode.xml")); _dtProducts = new DataTable(); _dtProducts = ds.Tables[0]; DataRow row = _dtProducts.NewRow(); for (int i = 0; i < _dtProducts.Rows.Count;i++ ) { row["pk_animalid"] = _dtProducts.Rows[i]["pk_animalid"].ToString(); row["AnimalCode"] = _dtProducts.Rows[i]["AnimalCode"].ToString(); row["ManualAnimalCode"] = _dtProducts.Rows[i]["ManualAnimalCode"].ToString(); } return row; } } } #endregion /// <summary> /// This event handler is used to fill the suggest list that appears as the user types /// Usually you would query a database, but for the sake of simplicity we are querying an in-memory datatable /// </summary> void asbProduct_TextChanged(object source, Anthem.AutoSuggestEventArgs e) { //Creates a dataview of the session's datatable DataView dv = new DataView(_dtProducts); //Filters the datatable based on the CurrentText property dv.RowFilter = string.Format("AnimalCode LIKE '%{0}%'", e.CurrentText); //Sets the dataview as the control's datasource asbProduct.DataSource = dv; asbProduct.DataBind(); } protected void adddet_Click(object sender, EventArgs e) { if (asbProduct.Text == "" || asbProduct.Text == null) { ClientMessaging("Enter the Animal Code Number..."); } D_ddlanimal.Items.Clear(); D_ddlanimal.Items.Insert(0, "--Select--"); D_ddlanimal.SelectedIndex = 0; D_ddlanimal.Items.Add(asbProduct.Text); D_ddlanimal.SelectedIndex = D_ddlanimal.SelectedIndex + 1; //DataRow dr = Filltbl(); //D_ddlanimal.DataTextField = dr["AnimalCode"].ToString(); //D_ddlanimal.DataValueField = dr["pk_animalid"].ToString(); }}
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)