I have the following webDropDown inside an update panel:
//Sets the selected value as the text, rather than the selected text function webDropDown_SelectionChanging(sender, e) { e.get_value()[0].set_text(e.get_value()[0].get_value()); }
On page load:
With departments .SQL = "SELECT DI.DEPARTMENT DEPT, DI.DEPARTMENT_DESC DESCR FROM COMMISH.DEPARTMENT_INFO DI WHERE DI.ACTIVE_FLAG = 'Y' ORDER BY DEPARTMENT_NUMBER" If .Select_Records_Custom_SQL(dtData) Then Me.wddDepartment.DataSource = dtData Me.wddDepartment.ValueField = "DEPT" Me.wddDepartment.TextField = "DESCR" Me.wddDepartment.DataBind() Me.wddDepartment.NullText = " " 'uwcDepartment.DataSource = dtData 'uwcDepartment.DataBind() End If End With
When user clicks search:
wddDepartment.CurrentValue = CStr(.Order_Department)
Everything works like I want it to, with one exception. When the user clicks search and the dropdown list value is updated, the dropdown width ignores its 50px width setting and is set to some default value. First question obviously is why does it do this? And second, how do I get it to remain at the 50px setting?
Edit: If I remove the page_load function where I populate the dropdown list, the width does not change.
Hello,
There are actually two different setting for the WebDropDown Width. The first one is managing the WDD's input width itself and the second one is managing the width of the container for the WDD Items.Width="50px"DropDownContainerWidth="400px" Both could differ and yet I suggest keeping these the same for better user experience. By default, if you would like to set the containerWidth to be wide enough to match the width of the longest items inside, you could use empty string for it like:DropDownContainerWidth=""I am attaching a runnable code sample illustrating this. Both widths are set via the Markup.
Please let me know if you require further assistance. In such case, please feel free to modify my sample with your approach, so I could take a look at the actual code in use.
I do have DropDownContainerWidth set, and I cannot have them both the same. I need width to be smaller than the DropDownContainerWidth. When the user clicks search and the dropdowns are updated, they do not go to the DropDownContainerWidth setting - apparently there is some default setting, and the dropdowns change to that size.
It should be simple to see this. Set up a dropdown that gets populated by a datasource on page load. Then set up a button to set the dropdown to a string when the button is clicked. Here is the simplest example I can give from my project:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
drConfirm = dtConfirm.NewRow() drConfirm("value") = "Y" drConfirm("key") = "Yes" dtConfirm.Rows.Add(drConfirm)
drConfirm = dtConfirm.NewRow() drConfirm("value") = "N" drConfirm("key") = "No" dtConfirm.Rows.Add(drConfirm)
Me.wddConfirm.DataSource = dtConfirm Me.wddConfirm.TextField = "key" Me.wddConfirm.ValueField = "value" Me.wddConfirm.DataBind() Me.wddConfirm.NullText = "N"
Protected Sub ibtnSearch_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnSearch.Click
wddConfirm.CurrentValue = "N"
End Sub
Thank you for the details shared. Did you had the chance to look at my code attachment? It seems you are describing exactly what I have done in the attached sample – setting DS on Page Load as well as setting both widths via the markup. What is more, I have handled the button click as you are using WebDropDown1.CurrentValue = "N"; and I am attaching the modified sample for reference. Both WDD widths are persisted when set via the markup. Please let me know how you are setting the widths. Are you doing it in the Markup, or you are using code behind? This code is missing from your code snippets. Please refer to the attachment and if you have more questions implementing this approach. It could be easier to modify the sample using your approach if it differs, in case the shared one is not suitable for you. Additionally, knowing the exact product version you are using could further help narrow this issue down.
Please let me know if you require further assistance.
The main difference I see is that I am creating a data source and creating text and value fields that are different from each other, and you are just adding a list of values. The text and value of each item in your dropdown will be the same, unlike mine.
Also, I am setting widths in the HTML:
<ig:WebDropDown ID="wddDepartment" runat="server" Width="50px" DropDownContainerWidth="400px"> <ClientEvents SelectionChanging="webDropDown_SelectionChanging" /> </ig:WebDropDown>
I am glad you found the cause of this. I suggest you to use the latest available Service Release for the product, as this seems to be not reproducible with the latest one available.
I think I found what is causing it. For some reason I left out one piece of code that is causing this:
Me.wddDeliverTo.NullText = " "
or in HTML:
NullText=" "
If either of these are set, the strange behavior happens. If I don't have this, then it will show a selected value even if nothing is set.
Thank you for the additional code snippet. However, I could still not reproduce the wrong behavior you are describing. I have searched via our internal system and could not find any similar issues to be reported. I have modified the sample to match yours and it works as expected. I suggest you test it on your side and see the behavior for yourself. Additionally, what is the exact product version you are using?
Here is a somewhat working example, although I am using VB, not C#, so there will probably be a couple changes for you to make to get it to work.
Hello Jesse,
In order to further investigate this issue, it will be best if you modify the attached file or create a new one illustrating the approach. This will speed up the process of investigating the matter and reproducing the issue, as I could debug the actual code in use.