ASP.NET drop-down list and dictionary

I am using C#’s drop-down list in ASP.NET.

I am trying to bind a dictionary to the drop-down list.

How to specify “text” (the key of the dictionary is the drop-down text) and “value” (value) for the drop-down list?

Can you please help?

Note: There is a constraint that classes should not be introduced for this purpose. This is why I tried to use a dictionary.

Thank you

Lijo

Set the drop-down list to use keys and values, as shown below:

dropdown.DataValueField = "Key";
dropdown.DataTextField = "Value";
dropdown.DataSource = myDictionary;
dropdown.DataBind();

Since you actually bind KeyValuePair to each project, the properties you want to access are Key and Value.< /p>

I use C#’s drop-down list in ASP.NET.

I am trying to bind a dictionary to the drop-down list.

How to specify “text” (the key of the dictionary is the drop-down text) and “value” (value) for the drop-down list?

Can you please help?

Note: There is a constraint that classes should not be introduced for this purpose. This is why I tried to use a dictionary.

Thank you

Lijo

Set the drop-down list to use keys and values ​​as follows:

dropdown.DataValueField = " Key";
dropdown.DataTextField= "Value";
dropdown.DataSource = myDictionary;
dropdown.DataBind();

Because you will actually KeyValuePair is bound to each item, so the properties you want to access are Key and Value.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2120 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.