c# - How I can pass data from a database to a "select tag" in ASP.NET? -
I'm new to ASP.NET, and I can set the data from Area Now my code ASPX ASPX.CS select to Trying How can I decide it?
ID_Area | ID_Formula | Nombre
& asp: content runat = "server" ContentPlaceHolderID = "ContentPlaceHolder1" & gt; & Lt; Div class = "container" & gt; & Lt; Div class = "row" & gt; & Lt; Div class = "col-md-6" & gt; & Lt; Div class = "form-group" & gt; & Lt; Label & gt; Nambre de Region & lt; / Labels & gt; & Lt; ASP: Text Box Runat = "Server" id = "Region" CssClass = "Form-Control" Required = "True" & gt; & Lt; / Asp: text box & gt; & Lt; / Div & gt; & Lt; Div class = "form-group" & gt; & Lt; Label & gt; Formula Essaciada & lt; / Labels & gt; & Lt; Select ID = "selection1" run = "server" name = "d1" & gt; & Lt; / Select & gt; & Lt; / Div & gt; & Lt; Div class = "form-group" & gt; & Lt; Asp: button id = "btn_login" OnClick = "docreatearea" CssClass = "BTN BTN-Primary BTN-LG BTN-Block" text = "guider" runat = "server" /> & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt;
Secure Zero Page_load (Object Sender, EventArgs e) {if (! IsPostBack) {string query = @ "SELECT * FROM FORMULA"; (SqlConnection conn = New SqlConnection (Configuration Manager. Select Connection ["BancoEstadoConnectionString"]. ToString ()) {SqlCommand comand = new SqlCommand (query, conn); Dataset ds = new dataset (); Comand.Fill (DS, "Area"); Conn.Open (); Select1.DataSource = DS; Select1.DataTextField = "Nombre"; Select1.DataValueField = "Nombre"; Select1.DataBind ();
You must use an SqlDataAdapter to fill your dataset:
< Using the code> (SqlConnection conn = new SqlConnection (ConfigurationManager.ConnectionStrings ["BancoEstadoConnectionString"]). ToString ()) {SqlCommand comand = new SqlCommand (query, conn); Dataset ds = new dataset (); Conn.Open (); Var Adapter = New SqlDataAdapter (Command); Adapter.Fill (DS, "Author"); Select1.DataSource = DS; Select1.DataTextField = "au_fname"; Select1.DataValueField = "au_fname"; Select1.DataBind (); }
Comments
Post a Comment