(1) Select drop-down box
Front End: <select name= "gameserverlist" id= "gameserverlist" runat= "Server" ></select>
<button onclick= "Btnfun ()" > Test </button>
JS gets the currently selected value:
function Btnfun () {varobj = document.getElementById ("gameserverlist");//Location ID varindex = Obj.selectedindex;//Check Index varText = Obj.options[index].text;//Select text varvalue = Obj.options[index].value;//checked ValuesAlert (text+"["+value+"]"); }
Back end:
HtmlSelectSelect= (HtmlSelect) FindControl ("gameserverlist"); if(!IsPostBack) {DataTable table=NewDataTable (); Table= This. Getgameserverlistdata (); if(Table! =NULL) {ListItem Itemson=NULL; stringtext="", val =""; foreach(DataRow rowinchtable. Rows) {text= row["server_name"] ==NULL?"": row["server_name"]. ToString (); Val= row["server_id"] ==NULL?"": row["server_id"]. ToString (); Itemson=NewListItem (Text,val); Select. Items.Add (Itemson); } } }
Aps.net WebForm Framework Page Server-side controls and HTML control usage