Du får lige et par eksempler som forhåbentlig kan bringe dig videre...
Først en aspx-fil:
<%@ Page language="c#" Codebehind="Binding.aspx.cs" AutoEventWireup="false" Inherits="Snippets.EkspertenTries.Binding" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Binding</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="
http://schemas.microsoft.com/intellisense/ie5"> </HEAD>
<body>
<form id="Form1" method="post" runat="server">
<P>
<asp:TextBox id="txt1" runat="server" Width="100px"></asp:TextBox><br>
<asp:TextBox id="txt2" runat="server" Width="100px"></asp:TextBox><BR>
<asp:DropDownList id="dd" runat="server" Width="100px"></asp:DropDownList><BR>
<asp:Button id="btn" runat="server" Text="Button" Width="100px"></asp:Button>
</P>
<P>
<asp:TextBox id=txtDb1 runat="server" Text="<%# SomeString %>" Width="100px"></asp:TextBox><BR>
<asp:TextBox id="txtDb2" runat="server" Text="<%# SomeInt %>" Width="100px"></asp:TextBox><BR>
<asp:DropDownList id="ddDb" runat="server" Width="100px" DataSource="<%# SomeArray %>"></asp:DropDownList><BR>
<asp:Button id="btnDb" runat="server" Text="<%# ButtonText %>" Width="100px"></asp:Button>
</P>
</form>
</body>
</HTML>
Og en code-behind fil i C#
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Snippets.EkspertenTries
{
/// <summary>
/// Summary description for Binding.
/// </summary>
public class Binding : System.Web.UI.Page
{
// textbokse
protected System.Web.UI.WebControls.TextBox txt1;
protected System.Web.UI.WebControls.TextBox txt2;
// databundne textbokse
protected System.Web.UI.WebControls.TextBox txtDb1;
protected System.Web.UI.WebControls.TextBox txtDb2;
// dropdownlist
protected System.Web.UI.WebControls.DropDownList dd;
// databundet dropdownlist
protected System.Web.UI.WebControls.DropDownList ddDb;
// knap
protected System.Web.UI.WebControls.Button btn;
// knap med databunden tekst
protected System.Web.UI.WebControls.Button btnDb;
// variable
protected string SomeString = "et eller andet...";
protected int SomeInt = 100;
protected string[] SomeArray = {"Hej","med","dig"};
protected string ButtonText = "Reload";
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
// programmatisk angivelse
this.txt1.Text = SomeString;
this.txt2.Text = SomeInt.ToString();
this.dd.DataSource = SomeArray;
foreach(string s in SomeArray)
{
dd.Items.Add(new ListItem(s,s));
}
this.btn.Text = ButtonText;
// databinding
DataBind();
}
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
}
}
Håber du kan bruge det til noget - mvh.