Jump to content

[Resolvido] Pesquisar à medida que se vai escrevendo a palavra


Recommended Posts

Posted

Boas pessoal,

A minha duvida é a seguinte, quero fazer uma pesquisa num campo numa pagina da web onde tem várias opcções, e o tipo de pesquisa que quero fazer é eu ao escrever por exemplo as 2 letras ou as 3 letras iniciais da palavra e aparecer logo uma opção dessa palavra que existe na lista.

O meu código é o seguinte:

<div class="controlRow">
		 <b>Marca</b> do Veículo
		 <br />
		 <telerik:RadComboBox ID="rcbBrand" runat="server" CssClass="rcbControl" TabIndex="1" />
	 </div>

Muito Obrigado

Posted

Já estive a debruçar no assunto mas estou com o problema que é o seguinte, a comboBox quando começo a digitar as letras faz loading sempre que teclo um letra mas não me vi buscar o que tenho na lista passo a demonstrar o código que fiz para o caso de alguém me conseguir ajudar.

Página aspx:

<div class="controlRow">
		 <b>Marca</b> do Veículo
		 <br />
		 <telerik:RadComboBox ID="rcbBrand" runat="server" CssClass="rcbControl" TabIndex="1"
				 DataTextField="CarBrand" EnableLoadOnDemand="True" ShowMoreResultsBox ="true" />
	 </div>

E agora a CodeBehind desta página mais própriamente a parte do código onde actualmente está a ser carregada a lista das marcas de automóveis:

protected void Page_Load(object sender, EventArgs e)
 {
	 if (!Page.IsPostBack)
	 {
		 this.btnSave.Attributes.Add("onclick", Helper.DisableTheButton(this.Page, this.btnSave));
		 try
		 {
			 if (HttpContext.Current.User.IsInRole("Locked"))
			 {
				 btnSave.Enabled = false;
			 }
			 rcbBrand.DataSource = PaySimplexWebLayers.Business.ParkingBLL.ListCarBrands();
			 rcbBrand.DataValueField = "CarBrandId";
			 rcbBrand.DataTextField = "CarBrand";
			 rcbBrand.DataBind();
		 }
		 catch
		 {
			 lblStatus.Text = "Ocorreu um erro inesperado.";
		 }
	 }
 }	

O que poderei a estar a fazer mal?

Obrigado

Posted

Penso que o método que precisas de implementar seja o equivalente a este (ficheiro Products.cs, no link que te indiquei):

    public RadComboBoxData GetCompanyNames(RadComboBoxContext context)
    {
         string sql = "SELECT * from Customers WHERE CompanyName LIKE @text + '%'";

         SqlDataAdapter adapter = new SqlDataAdapter(sql,
              ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
         DataTable data = new DataTable();

       adapter.SelectCommand.Parameters.AddWithValue("@text", context.Text);
         adapter.Fill(data);

         List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(context.NumberOfItems);
         RadComboBoxData comboData = new RadComboBoxData();
         try
         {

              int itemsPerRequest = 10;
              int itemOffset = context.NumberOfItems;
              int endOffset = itemOffset + itemsPerRequest;
              if (endOffset > data.Rows.Count)
              {
                   endOffset = data.Rows.Count;
              }
              if (endOffset == data.Rows.Count)
              {
                   comboData.EndOfItems = true;
              }
              else
              {
                   comboData.EndOfItems = false;
              }
              result = new List<RadComboBoxItemData>(endOffset - itemOffset);
              for (int i = itemOffset; i < endOffset; i++)
              {
                   RadComboBoxItemData itemData = new RadComboBoxItemData();
                   itemData.Text = data.Rows[i]["CompanyName"].ToString();
                   itemData.Value = data.Rows[i]["CompanyName"].ToString();

                   result.Add(itemData);
                   }

              if (data.Rows.Count > 0)
              {
                   comboData.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), data.Rows.Count.ToString());
              }
              else
              {
                   comboData.Message = "No matches";
              }
         }
         catch(Exception e)
         {
              comboData.Message = e.Message;
         }

         comboData.Items = result.ToArray();
         return comboData;
    }

Mas não conheço os detalhes das bibliotecas que estás a usar.

  • 3 weeks later...
Posted

Pessoal já agora mais uma pequena duvida, eu tenho numa caixa de texto em que o utilizador escreve um numero e no fim automaticamente aparece um simbolo, mas queria que esse simbolo aparece-se em vez de no fim no inicio, é possível?

ty

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.