Click here to Skip to main content
15,908,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There is one dropdownbox on my webform which has all wholesaler name after selecting one wholesaler name from dropdown user will type the product name in productname textbox while typing i am providing the all productname list of that wholesaler in listbox which gets fill on txtproductname change event but while typing each letter every time form gets refresh so how could i avoid this, i need it very badly thanx in advance, for above purpose on selecting wholesaler name i loaded all product in string of array and also on forms load i checked if form is reloaded due to postback then i again loaded all product name again in string of array and then on textchange event i use ling to array to populate the list box below is my code

C#
public partial class PlaceOrdrLnq : System.Web.UI.Page
{
    int total = 0;
     
     string[] strarr;
     ArrayList obj = new ArrayList();

    protected void Page_Load(object sender, EventArgs e)
    {
       
        double SMId = 0;
        double RetId = 0;
        //Page.GetPostBackEventReference(TextBox1);
        TextBox1.Attributes.Add("OnKeyUp", "javascript:return __doPostBack()");

        if (!IsPostBack)
        {
..
.
}
else // by avi for textbox 1 change event on10/6/12
{
DataTable dt = Commanclass.returnData("Select product+'==='+Packsize as product from WholeSalerStock where wholesalerid=" + ddlWholeSaler.Text + "");
DataRow[] dr = dt.Select();
strarr = Array.ConvertAll(dr, new Converter<datarow,>(DataRowToString));
TextBox1.Focus();
}
}

protected void ddlWholeSaler_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblMsg.Text = "";
        try
        {
           
            DataTable dt = Commanclass.returnData("Select product+'==='+Packsize as product from WholeSalerStock where wholesalerid=" + ddlWholeSaler.Text + "");
            DataRow[] dr = dt.Select();
            strarr = Array.ConvertAll(dr, new Converter<datarow,>(DataRowToString));           
            
            LoadProductPacksize();

            string msg = Convert.ToString(Commanclass.returnData("select TextMessage from dbo.Message where RegId =" + ddlWholeSaler.SelectedValue + " and Approved=1").Rows[0]["TextMessage"]);
            lblMsg.Text = "Message From WholeSaler\n <center>" + msg + "</center>";

        }
        catch { lblMsg.Text = "No Message"; }
    }


   public static string DataRowToString(DataRow dr)
    {
        return dr["Product"].ToString();
    }

 public void TextBox1_TextChanged(object sender, EventArgs e)
    {

        if (TextBox1.Text != "")
        {
           
            ListBox1.Items.Clear();
          
            ListBox1.DataSource = from str in strarr where str.ToUpper().StartsWith(TextBox1.Text.ToUpper()) select str;
            ListBox1.DataBind();

       
            ListBox1.Visible = true;
        }

        
    }



    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ListBox1.SelectedItem.Text != "")
        {
            TextBox1.Text = ListBox1.SelectedItem.Text;
            ListBox1.Visible = false;
        }
    }


only Code block updated
Posted
Updated 7-Jul-12 2:44am
v3
Comments
bbirajdar 7-Jul-12 9:54am    
Do you know there is a 'fullstop' key on the keyboard and has to be used for seperating sentences... ???

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