locked
Very WIDE dropdownlist. using Dynamic data futures!! RRS feed

  • Question

  • User-1759624489 posted

     Hello.

    I have  a table called elementcharacteristics, which has a field of type nvarchar(MAX),

     

    I have a table called parameters.

     

    One elementcharacteristic may have many parameters.

     

    The problem is that when I go to the Parameter page, it shows me in a dropdownlist the elementcharacteristics.

     

    But that text is too long and the dropdown looks very ugly

     

    I was trying to put UIHINT("Text"), but that will not work

     

    ANy idea please!!!

    Tuesday, September 16, 2008 4:28 PM

Answers

  • User-1005219520 posted

    I solved the problem by adding the following to the filterUserControl

     

      protected void Page_Init(object sender, EventArgs e) {
            if (!Page.IsPostBack) {
                PopulateListControl(DropDownList1);
    
                for (int i = 0; i < DropDownList1.Items.Count; i++) {
                    string s = DropDownList1.Items[i].Text;
    
                    int maxLen = 44;
                    for (int j = 0; j < s.Length; j++)
                        if (s[j] > 127) {
                            maxLen /= 2;
                            break;
                        }
    
                    if (s.Length > maxLen) {
                        s = s.Substring(0, maxLen - 2);
                        s += " ... (see Details for full)";
                        DropDownList1.Items[i].Text = s;
                    }
                }
    
                // Set the initial value if there is one
                if (!String.IsNullOrEmpty(InitialValue))
                    DropDownList1.SelectedValue = InitialValue;
            }
        }
     
    It's not a great solution as text area is dependent on local/language.  That should give you a starting point.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 16, 2008 5:18 PM
  • User-1759624489 posted

    I solved my self

     

    Moving the code to the page_load and after the populatecontrol method, otherwise it wont work.

     

      protected void Page_Load(object sender, EventArgs e) {
            if (DropDownList1.Items.Count == 0)
            {
                if (!Column.IsRequired)
                {
                    DropDownList1.Items.Add(new ListItem("[Not Set]", ""));
                }

                PopulateListControl(DropDownList1);
                if (DropDownList1 != null)
                {
                    for (int i = 0; i < DropDownList1.Items.Count; i++)
                    {
                        string s = DropDownList1.Items[i].Text;

                        int maxLen = 44;
                        for (int j = 0; j < s.Length; j++)
                            if (s[j] > 127)
                            {
                                maxLen /= 2;
                                break;
                            }

                        if (s.Length > maxLen)
                        {
                            s = s.Substring(0, maxLen - 2);
                            s += " ... (Ver Detalles)";
                            DropDownList1.Items[i].Text = s;
                        }
                    }
                }
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 16, 2008 6:08 PM

All replies

  • User-1759624489 posted

     I have a crazy idea but I dont know where to put that code.

     

    I put this

       [ScaffoldColumn(false)]
            [Filter(Enabled=false)]
            public object ElementCharacteristic { get; set; }

     

    but it doesnt insert, I guess why, because its not sending the ElementCharacteristicId.

     

    But I can take that value from the querystring.

     

    The problem I dont know exactly where to put that code

     

    thx

    Tuesday, September 16, 2008 5:04 PM
  • User-1005219520 posted

    I solved the problem by adding the following to the filterUserControl

     

      protected void Page_Init(object sender, EventArgs e) {
            if (!Page.IsPostBack) {
                PopulateListControl(DropDownList1);
    
                for (int i = 0; i < DropDownList1.Items.Count; i++) {
                    string s = DropDownList1.Items[i].Text;
    
                    int maxLen = 44;
                    for (int j = 0; j < s.Length; j++)
                        if (s[j] > 127) {
                            maxLen /= 2;
                            break;
                        }
    
                    if (s.Length > maxLen) {
                        s = s.Substring(0, maxLen - 2);
                        s += " ... (see Details for full)";
                        DropDownList1.Items[i].Text = s;
                    }
                }
    
                // Set the initial value if there is one
                if (!String.IsNullOrEmpty(InitialValue))
                    DropDownList1.SelectedValue = InitialValue;
            }
        }
     
    It's not a great solution as text area is dependent on local/language.  That should give you a starting point.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 16, 2008 5:18 PM
  • User-1759624489 posted

    Hi, that worked perfect for the  filter, but I need it for inserting-editing.

     I tried this on the Foreign Key Edit

     

     protected override void OnInit(EventArgs e)
        {
            if (DropDownList1 != null)
            {
                for (int i = 0; i < DropDownList1.Items.Count; i++)
                {
                    string s = DropDownList1.Items[i].Text;

                    int maxLen = 44;
                    for (int j = 0; j < s.Length; j++)
                        if (s[j] > 127)
                        {
                            maxLen /= 2;
                            break;
                        }

                    if (s.Length > maxLen)
                    {
                        s = s.Substring(0, maxLen - 2);
                        s += " ... (see Details for full)";
                        DropDownList1.Items[i].Text = s;
                    }
                }
            }  
        
            base.OnInit(e);
        }

     

     

    but it still shows me the very WIDE dropdownlist.

     

    Thx

    Tuesday, September 16, 2008 6:00 PM
  • User-1759624489 posted

    I solved my self

     

    Moving the code to the page_load and after the populatecontrol method, otherwise it wont work.

     

      protected void Page_Load(object sender, EventArgs e) {
            if (DropDownList1.Items.Count == 0)
            {
                if (!Column.IsRequired)
                {
                    DropDownList1.Items.Add(new ListItem("[Not Set]", ""));
                }

                PopulateListControl(DropDownList1);
                if (DropDownList1 != null)
                {
                    for (int i = 0; i < DropDownList1.Items.Count; i++)
                    {
                        string s = DropDownList1.Items[i].Text;

                        int maxLen = 44;
                        for (int j = 0; j < s.Length; j++)
                            if (s[j] > 127)
                            {
                                maxLen /= 2;
                                break;
                            }

                        if (s.Length > maxLen)
                        {
                            s = s.Substring(0, maxLen - 2);
                            s += " ... (Ver Detalles)";
                            DropDownList1.Items[i].Text = s;
                        }
                    }
                }
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 16, 2008 6:08 PM