Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding datasource to an html <select> tag

Tags:

asp.net

Is there any way to bind a datasource to an html select tag with runat=server attribute.

<select runat="server" onchange="showdistrict();" class="textbox" id="DpCity" name="DpCity">
    <option value="0">unknow</option>
</select>
like image 673
Raymond Morphy Avatar asked Sep 11 '25 08:09

Raymond Morphy


1 Answers

I found the answer myself so I'll share it. by using runat="server" attribute and assigning an id to control it will be accessible in code behind. for example DpCity is my html select tag so I can use below code for binding datasource:

DpCity.DataTextField = "title";
        DpCity.DataValueField = "val";
        DpCity.DataSource = SrCity;
        DpCity.DataBind();

as like as an asp dropdown list box

like image 174
Raymond Morphy Avatar answered Sep 14 '25 00:09

Raymond Morphy