Problems encountered when drowdownlist has the same value

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.