E-mail
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebSite2testWebProj._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 id="Head1" runat="server"> <title>Untitled Page</title> </head> <body> <form id="form2" runat="server"> <div> hello world from html<br /> <%= "Hello from asp.net" %> <br /> This is a label: <asp:Label ID="label1" runat="server" /> <br /> The time is: <%= System.DateTime.Now.ToLongTimeString()%> <br /> This is a textbox: <asp:TextBox runat="server" ID="textbox1" /><br /> A button: <asp:Button runat="server" ID="button1" Text="press me" onclick="button1_Click" /><br /> Label2 is here: <asp:Label ID="label2" runat="server" /><br /> asp.net uses viewstate.. so the button is just a submit button, which then goes back to the server, refreshes the page with the new data in the label2 label. <br /> </div> Autopostback is set in the following DropDownList (server control)... makes contact with the server each time an item is selected.. which we can use to wire up an event..onselectedindexchanged<br /> <asp:DropDownList runat="server" ID="GreetList" AutoPostBack="true" onselectedindexchanged="GreetList_SelectedIndexChanged"> <asp:ListItem Value="no one">No one</asp:ListItem> <asp:ListItem Value="world">World</asp:ListItem> <asp:ListItem Value="universe">Universe</asp:ListItem> </asp:DropDownList><br /> Label3: <asp:Label ID="label3" runat="server" /> <br /> </form> </body> </html>
using System; using System.Web.UI; namespace WebSite2testWebProj { public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { Response.Write("Hello from Page_Load in codebehind"); label1.Text = "Hello from the codebehind into a label"; textbox1.Text = "Textbox from codebehind"; } protected void button1_Click(object sender, EventArgs e) { label2.Text = "button pressed"; } protected void GreetList_SelectedIndexChanged(object sender, EventArgs e) { label3.Text = "Hello, " + GreetList.SelectedValue; } } }
<form id="form1" runat="server"> <div> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TreasureConnectionString %>" SelectCommand="SELECT [StuffId], [Description] FROM [Stuff]"></asp:SqlDataSource> <br /> <br /> this is a gridview <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="StuffId" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="StuffId" HeaderText="StuffId" InsertVisible="False" ReadOnly="True" SortExpression="StuffId" /> <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" /> </Columns> </asp:GridView> <br /> this is a datalist<br /> <br /> <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" > <ItemTemplate> <asp:Literal ID="Literal2" runat="server" Text="Description:"></asp:Literal> <asp:Literal ID="Literal1" runat="server" Text='<%# Eval("Description") %>'></asp:Literal> </ItemTemplate> <EditItemTemplate> <asp:Literal ID="Literal2" runat="server" Text="Description:"></asp:Literal> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Description") %>' Width="208px"></asp:TextBox> </EditItemTemplate> </asp:DataList><br /> <br /> this is a details view</div> <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" CellPadding="4" DataKeyNames="StuffId" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Height="50px" Width="341px"> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" /> <EditRowStyle BackColor="#2461BF" /> <RowStyle BackColor="#EFF3FB" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <Fields> <asp:BoundField DataField="StuffId" HeaderText="StuffId" InsertVisible="False" ReadOnly="True" SortExpression="StuffId" /> <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" /> </Fields> <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" /> </asp:DetailsView> <br /> <br /> </form>
<connectionStrings> <add name="TreasureConnectionString" connectionString="Data Source=localhost;Initial Catalog=Treasure;Persist Security Info=True;User ID=dave;Password=letmein" providerName="System.Data.SqlClient"/> </connectionStrings>
A gridview with update <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TreasureConnectionString %>" SelectCommand="SELECT [StuffId], [Description] FROM [Stuff]" UpdateCommand="UPDATE Stuff SET Description=@Description WHERE StuffID=@StuffID"> </asp:SqlDataSource> <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="StuffId" AutoGenerateEditButton="true" DataSourceID="SqlDataSource2"> <Columns> <asp:BoundField DataField="StuffId" HeaderText="StuffId"/> <asp:BoundField DataField="Description" HeaderText="Description"/> </Columns> </asp:GridView>
Remember Me
a@href@title, strike