When I was working on a project today, I encountered a small problem when using drowdownlist. Let's record it. It's a very simple problem. I hope you don't need to make a brick.
Drowdownlist is used in the project today. You need to load the user's role list for selection. However, each role corresponds to a different permission (three types in total, expressed in, 2 ), when selecting an option, you need both the role name and the role permissions. So I started to use text to record the role name (unique) and value to record the role permissions, there are three permissions in total, so the value must have repeated records. At that time, we thought it should be okay, but there was a problem during the selection. In addition, some other information will be automatically updated when items in the drowdownlist are selected in the project, that is, autopostback is enabled. If it is not enabled, this problem should not occur.
The dropdownlist code is as follows (data is bound ):
<Asp: dropdownlist id = "ddlrole" runat = "server" autopostback = "true" onselectedindexchanged = "ddlrole_selectedindexchanged">
<Asp: listitem value = "0"> A </ASP: listitem>
<Asp: listitem value = "1"> B </ASP: listitem>
<Asp: listitem value = "2"> C </ASP: listitem>
<Asp: listitem value = "0"> d </ASP: listitem>
<Asp: listitem value = "1"> E </ASP: listitem>
<Asp: listitem value = "0"> F </ASP: listitem>
</ASP: dropdownlist>
In this way, only a is selected when a, d, and F are selected. At that time, I thought it was a problem of automatically submitting functions, but I didn't have any problems after debugging for half a day. Later I thought it was a problem of having the same nominal value in the value.
So I changed the code:
<Asp: dropdownlist id = "ddlrole" runat = "server" autopostback = "true" onselectedindexchanged = "ddlrole_selectedindexchanged">
<Asp: listitem value = "0a"> A </ASP: listitem>
<Asp: listitem value = "1B"> B </ASP: listitem>
<Asp: listitem value = "2C"> C </ASP: listitem>
<Asp: listitem value = "0d"> d </ASP: listitem>
<Asp: listitem value = "1E"> E </ASP: listitem>
<Asp: listitem value = "0f"> F </ASP: listitem>
</ASP: dropdownlist>
In this way, the above problems will not occur after the selection. However, when reading the value, you need to perform an operation that only takes the first digit.
This is a small problem encountered in the project, hoping to help people with the same problem. If any, please forgive me.