<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>asp.net FormView example: how to use ItemTemplate, Eval()</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Teal">FormView ItemTemplate Example</h2>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT CustomerID, CompanyName FROM Customers"
>
</asp:SqlDataSource>
<asp:DropDownList
ID="DropDownList1"
runat="server"
DataSourceID="SqlDataSource1"
DataTextField="CompanyName"
DataValueField="CustomerID"
AutoPostBack="true"
>
</asp:DropDownList>
<asp:SqlDataSource
ID="SqlDataSource2"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address FROM Customers WHERE CustomerID=@CustomerID"
>
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="CustomerID" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<br /><br />
<asp:Panel ID="Panel1" runat="server" ForeColor="Crimson">
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource2">
<ItemTemplate>
<i>
<b>Customer ID: </b>
<%# Eval("CustomerID") %>
<br />
<b>Company Name: </b>
<%# Eval("CompanyName") %>
<br />
<b>Contact Name: </b>
<%# Eval("ContactName") %>
<br />
<b>Contact Title: </b>
<%# Eval("ContactTitle") %>
<br />
<b>Address: </b>
<%# Eval("Address") %>
</i>
</ItemTemplate>
</asp:FormView>
</asp:Panel>
</div>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>asp.net FormView example: how to use ItemTemplate, Eval()</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Teal">FormView ItemTemplate Example</h2>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT CustomerID, CompanyName FROM Customers"
>
</asp:SqlDataSource>
<asp:DropDownList
ID="DropDownList1"
runat="server"
DataSourceID="SqlDataSource1"
DataTextField="CompanyName"
DataValueField="CustomerID"
AutoPostBack="true"
>
</asp:DropDownList>
<asp:SqlDataSource
ID="SqlDataSource2"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address FROM Customers WHERE CustomerID=@CustomerID"
>
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="CustomerID" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<br /><br />
<asp:Panel ID="Panel1" runat="server" ForeColor="Crimson">
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource2">
<ItemTemplate>
<i>
<b>Customer ID: </b>
<%# Eval("CustomerID") %>
<br />
<b>Company Name: </b>
<%# Eval("CompanyName") %>
<br />
<b>Contact Name: </b>
<%# Eval("ContactName") %>
<br />
<b>Contact Title: </b>
<%# Eval("ContactTitle") %>
<br />
<b>Address: </b>
<%# Eval("Address") %>
</i>
</ItemTemplate>
</asp:FormView>
</asp:Panel>
</div>
</form>
</body>
</html>
No comments:
Post a Comment