The SqlDataSource, AccessDataSource, LinqDataSource, and ObjectDataSource controls all support the following types of Parameter objects:
Parameter: Represents an arbitrary static value.
ControlParameter: Represents the value of a control or page property.
CookieParameter: Represents the value of a browser cookie.
FormParameter: Represents the value of an HTML form field.
ProfileParameter: Represents the value of a Profile property.
QueryStringParameter: Represents the value of a query string field.
SessionParameter: Represents the value of an item stored in Session state.
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Show Control Parameter</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList
id="ddlProductCategory"
DataSourceID="srcProductCategories"
DataTextField="Name"
DataValueField="Id"
Runat="server" />
<asp:Button
id="btnSelect"
Text="Select"
ToolTip="Select Product"
Runat="server" />
<hr />
<asp:GridView
id="grdProducts"
DataSourceID="srcProducts"
Runat="server" />
<asp:SqlDataSource
id="srcProductCategories"
ConnectionString="Server=.\SQLExpress;
Trusted_Connection=True;AttachDbFileName=|DataDirectory|MyDatabase.mdf;
User Instance=True"
SelectCommand="SELECT Id,Name FROM ProductCategories"
Runat="server" />
<asp:SqlDataSource
id="srcProducts"
ConnectionString="Data Source=.\SQLExpress;
AttachDbFilename=|DataDirectory|MyDatabase.mdf;
Integrated Security=True;User Instance=True"
SelectCommand="SELECT Title,Director FROM Products
WHERE CategoryId=@Id"
Runat="server">
<SelectParameters>
<asp:ControlParameter
Name="Id"
Type="int32"
ControlID="ddlProductCategory" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
|