简体   繁体   中英

Passing values to html select from code behind

I have an html select in one of my aspx pages and I would like to assign it the option value from code behind.

<select id="pageSize" runat="Server">
        <option value="how to set it from c#?">All</option>

I have a property call MyPageCount of type int, how can i pass its value here?.

I would appreciate any help.

Regards

add runat="server" and then set pageSize.Value=MyPageCount; in codebehind

Have you tried this:

<option value="<%: this.MyPageCount.ToString() %>">All</option>

If it's inside a data bound control:

<option value='<%# Bind("YourField") %>'>All</option>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM