user710502
user710502

Reputation: 11469

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

Upvotes: 2

Views: 2638

Answers (2)

PraveenVenu
PraveenVenu

Reputation: 8337

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

Upvotes: 1

Jupaol
Jupaol

Reputation: 21365

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>

Upvotes: 0

Related Questions