Issuu on Google+

DropBox 'manuel befolkning' af combobox' myNerdStuff

Demo Projektet her kan vælge mellem tre forskellige punkter i dropdown menu, og når der klikkes på et punkt vises der en placering i en label th. for box.

Solution explorer ser ud som billede viser herunder.

Start med at lave en ny website og kald den feks ddltest, add en fil der hedder initNodeListe, og fyld koden herunde ind i filerne:

.Gratis guide fra myNerdStuff, platform: NET 4 / C# - Version 30-11-10

side 1 af 5


DropBox 'manuel befolkning' af combobox' myNerdStuff

Indhold af default.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:DropDownList ID="DropDownList1" runat="server" onselectedindexchanged="DropDownList1_SelectedIndexChanged" AppendDataBoundItems="True" AutoPostBack="True"> </asp:DropDownList> <asp:Label ID="lblSelection" runat="server" Text="Label"></asp:Label> </div> </form> </body> </html>

.Gratis guide fra myNerdStuff, platform: NET 4 / C# - Version 30-11-10

side 2 af 5


DropBox 'manuel befolkning' af combobox' myNerdStuff

Indhold af default.aspx.cs using using using using using using

System; System.Collections.Generic; System.Linq; System.Web; System.Web.UI; System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DropDownList1.Items.Add("solarDatalogger"); DropDownList1.Items.Add("stokerDatalogger"); DropDownList1.Items.Add("homeAutomation"); } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { if (DropDownList1.Text == "solarDatalogger") { lblSelection.Text = "også placeret i fyrrum"; } if (DropDownList1.Text == "stokerDatalogger") { lblSelection.Text = "placeret i fyrrum"; } if (DropDownList1.Text == "homeAutomation") { lblSelection.Text = "placeret i kælder"; } } }

.Gratis guide fra myNerdStuff, platform: NET 4 / C# - Version 30-11-10

side 3 af 5


DropBox 'manuel befolkning' af combobox' myNerdStuff

Indhold af initNodeListe.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="initNodeListe.aspx.cs" Inherits="initNodeListe" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="btnInitNodeListe" runat="server" Text="Initialiser Dropdownliste med Noder" onclick="btnInitNodeListe_Click" /> <asp:Label ID="lblStatus" runat="server" Text="status"></asp:Label> </div> </form> </body> </html>

.Gratis guide fra myNerdStuff, platform: NET 4 / C# - Version 30-11-10

side 4 af 5


DropBox 'manuel befolkning' af combobox' myNerdStuff

Indhold af initNodeListe.aspx.cs using using using using using using

System; System.Collections.Generic; System.Linq; System.Web; System.Web.UI; System.Web.UI.WebControls;

public partial class initNodeListe : System.Web.UI.Page { HusNodes mineHusNoder; protected void Page_Load(object sender, EventArgs e) { mineHusNoder = new HusNodes(1, "solarDatalogger"); mineHusNoder = new HusNodes(2, "stokerDatalogger"); mineHusNoder = new HusNodes(3, "homeAutomation"); } protected void btnInitNodeListe_Click(object sender, EventArgs e) { lblStatus.Text = mineHusNoder.buildNodeListe(); } }

.Gratis guide fra myNerdStuff, platform: NET 4 / C# - Version 30-11-10

side 5 af 5


dropdownbox i c#