Problem with ListBox

4 posts, 2 answers
  1. Ricardo
    Ricardo avatar
    113 posts
    Member since:
    Jul 2011

    Posted 04 Aug 2011 Link to this post

    Hello!

    I'm having a problem while trying to get the selected Item from a RadListBox...

    When i use the RadListBox1.SelectedItem.Value the value is allways null when i use a dictionary as my datasource, but the RadList has 26 rows....However i have other 2 listboxs whose datasource is an entity..i d'ont have any problem....
    Here is my code:
    public partial class AssignInvoices : Microsoft.Practices.CompositeWeb.Web.UI.Page, IAssignInvoicesView
        {
            private AssignInvoicesPresenter _presenter;
      
            //implemantaçao da propriedade
            public System.Collections.Generic.IList<Data.Users> Users
            {
                get;
                set;
            }
      
      
            public System.Collections.Generic.IList<Data.Priorities> Priorities
            {
                get;
                set;
            }
      
            public System.Collections.Generic.IList<Data.Staging> Staging
            {
                get;
                set;
            }
      
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!this.IsPostBack)
                {
                    this._presenter.OnViewInitialized();
                }
                this._presenter.OnViewLoaded();
      
                  
                  
                Info x = new Info("xx", "xx", "xx,DC=xx,DC=xx");
      
      
                Dictionary<string, string> networkUser = new Dictionary<string, string>();
                networkUser = x.GetHierarchyTree("xx");
      
                Dictionary<string, string> aux = new Dictionary<string, string>();
      
                foreach (KeyValuePair<string, string> kvp in networkUser)
      
                {
                    //kvp.Key = user de rede
                    string userCompName = x.GetUserInfo("cn", kvp.Key);
      
                    aux.Add(kvp.Key, userCompName);//Dictionary com key = user de rede e Value = nomeCompleto Utilizador
                      
                }
      
                RadListBox1.DataTextField = "Key";
                RadListBox1.DataValueField = "Value"; 
                RadListBox1.DataSource = aux;
                RadListBox1.DataBind();
      
                  
                //Page.User.Identity.Name para ir buscar o login user
      
      
                //Popular dados na listbox users
                //RadListBox1.DataSource = this.Users;
                //RadListBox1.DataTextField = "UserName";
                //RadListBox1.DataValueField = "UserSap";
                //RadListBox1.DataBind();
      
              
      
                //Popular dados na listbox grupos
                RadListBox2.DataSource = this.Priorities;
                RadListBox2.DataTextField = "Priority";
                RadListBox2.DataValueField = "Priority";
                RadListBox2.DataBind();
      
      
                //Popular dados na listbox stagins
                RadListBox3.DataSource = this.Staging;
                RadListBox3.DataTextField = "Process";
                RadListBox3.DataValueField = "Process";
                RadListBox3.DataBind();
      
      
            }
      
            [CreateNew]
            public AssignInvoicesPresenter Presenter
            {
                get
                {
                    return this._presenter;
                }
                set
                {
                    if (value == null)
                        throw new ArgumentNullException("value");
      
                    this._presenter = value;
                    this._presenter.View = this;
                }
            }
      
            // TODO: Forward events to the presenter and show state to the user.
            // For examples of this, see the View-Presenter (with Application Controller) QuickStart:
            //  
      
            protected void RadButton1_Click(object sender, EventArgs e)
            {
                string _UserValue = RadListBox1.SelectedItem.Value; //Gets the value of item in Users.
                              
                //string _text = RadListBox1.SelectedItem.Text;  //Gets the Text of items in the list. 
                List<string> _groups = new List<string>(); //create a list to store selected groups
                string _stg = RadListBox3.SelectedItem.Value; // create a list to store selected stagings
      
      
                if (RadListBox1.SelectedIndex > -1 && RadListBox2.SelectedIndex > -1 && RadListBox3.SelectedIndex > -1)
                {
      
                    iConnect.InvoicesScaling.Data.UsersAssignDAO usrAssgnDAO = new iConnect.InvoicesScaling.Data.UsersAssignDAO(new EscalonamentoFacturasEntities());
                    UsersAssign user = new UsersAssign();
      
      
                    foreach (var grp in RadListBox2.SelectedItems)
                    {
                        _groups.Add(grp.Value);  //store the selectItems on RadListBox2 to list groups   
      
                        //efectuar aqui o insert
      
                        user.InserDate = DateTime.Now;
                        int j;
                        Int32.TryParse(grp.Value, out j);
                        user.UserName = _UserValue;
                        user.Priority = j;
                        user.Staging = _stg;
      
                        //passar o objecto a inserir na tabela da bd
                        usrAssgnDAO.Add(user);
      
                        usrAssgnDAO.SaveChanges();
      
                    }
      
                      
      
                }
                //else if(RadListBox2.SelectedIndex < -1  )
                //reportar erro
      
      
      
            }
        }
    }
  2. Answer
    Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 09 Aug 2011 Link to this post

    Hi Ricardo,

    The problem that you are experiencing seems to be related to the fact that you bind your listbox upon each post-back and thus clearing the previously selected item. Please note that it's preferable to bind your control only once upon first page load. I've tested the RadListBox with Dictionary as a data source and everything was working as expected.

    Kind regards,
    Dimitar Terziev
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ricardo
    Ricardo avatar
    113 posts
    Member since:
    Jul 2011

    Posted 09 Aug 2011 Link to this post

    thanks a lot Dimitar..

    Can you help me on the topic http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-set-column-navigation-property.aspx? I'm a litle bit urgency on that thread :S
  5. Answer
    Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 12 Aug 2011 Link to this post

    Hi Ricardo,

    To avoid inconsistency of the tread, please open a new support ticket regarding RadGrid issue.

    Regards,
    Peter Filipov
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top