Aright, example time 
The main ASPX page looks something like this (I've actually stripped out the useless code that VS.NET puts in for maintenance purposes):
Code:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:DropDownList id=DropDownList1 style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 32px" runat="server" Width="216px">
</asp:DropDownList>
</form>
</body>
</HTML>
And the CodeBehind file:
Code:
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 WebApplication1
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected WebApplication1.DataSet1 dataSet11;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
sqlDataAdapter1.Fill(dataSet11 , "table1");
DropDownList1.DataBind();
}
}
}
In this example, the List isn't actually filled, but that's just a .Fill(), so no biggie. I've also removed the Form Designer code.
Define the area on the .aspx page (DW, Frontpage, VS.NET and Web Matrix will all see a drop down list). Designer does what he wants with the actual HTML. Presentational logic is done in the code-behind.
J
Bookmarks