Tuesday, October 12, 2010

set Rad Combobox to custom message when customtext is false

In an event where "AllowCustomText" is set to false, and you want to set the custom message and set the current index to less then zero so the first item is not already selected, leaving you the option to select the first available item in combobox and fire a postback event!






CodeBehind :

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            StockRep stockRep = new StockRep();
            var items = stockRep.FindAllActiveStocks();
            this.rcbRefNo.DataSource = items;
            this.rcbRefNo.DataTextField = "RefNo";
            this.rcbRefNo.DataValueField = "StockId";
            this.rcbRefNo.DataBind();

            RadComboBoxItem rcbi = new RadComboBoxItem();
            rcbi.Text = "--Select an Item--";
            this.rcbRefNo.Items.Insert(0, rcbi);
        }
    }

-

No comments:

Post a Comment