-->

22 December 2019

Asp.Net DataSource Controls with Parameter

  Asp.Net CS By Example       22 December 2019

 DataSource Controls with Parameter:  

  The DataSource control support the parameters. We can use Parameters to modify the commands that a
DataSource control executes. Different types of DataSource controls use ASP.NET parameters to represent
different types of things. When we use ASP.NET parameters with a SqlDataSource control, the ASP.NET
parameters represent ADO.NET parameters.

 In other words, they represent parameters used with SQL statements.
When we use parameters with the ObjectDataSource control, the ASP.NET parameters
represent method parameters. They represent parameters passed to a particular method of
a business object.

 The SqlDataSource, AccessDataSource, LinqDataSource, and ObjectDataSource controls
all support the following types of Parameter objects:
S.N. Parameter objects Description
1) Parameter Represents an arbitrary static value.
2) ControlParameter Represents the value of a control or page property.
3) CookieParameter Represents the value of a browser cookie.
4) FormParameter Represents the value of an HTML form field.
5) ProfileParameter Represents the value of a Profile property.
6) QueryStringParameter Represents the value of a query string field.
7) SessionParameter Represents the value of an item stored in Session state.

  Code: ShowControlParameterEx01.aspx 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ShowControlParameterEx01.aspx.cs"
    Inherits="LearnAsp.Net.ControlDemo.DataBound.ShowControlParameterEx01" %>

<!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>Show Control Parameter</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color: Teal">
            ControlParameter Example</h2>
        <asp:DropDownList ID="ddlDeptCategory" DataSourceID="srcDeptCategories" DataTextField="Name"
            DataValueField="id" runat="server" />
        <asp:Button ID="btnSelect" Text="Select" ToolTip="Select Department" runat="server" />
        <hr />
        <asp:GridView ID="grdEmployee" DataSourceID="srcEmployee" ForeColor="SlateGray" BackColor="Snow"
            BorderColor="HotPink" runat="server" />
        <asp:SqlDataSource ID="srcDeptCategories" ConnectionString="<%$ ConnectionStrings:constrOracle %>"
            ProviderName="System.Data.OracleClient" 
            SelectCommand="SELECT department_id id,department_name Name FROM departments where rownum <=10 "
            runat="server" />
        <asp:SqlDataSource ID="srcEmployee" ConnectionString="<%$ ConnectionStrings:constrOracle %>"
            ProviderName="System.Data.OracleClient"  runat="server"
            SelectCommand=" select * from employees WHERE department_id =:id">
            <SelectParameters>
                <asp:ControlParameter ControlID="ddlDeptCategory" Name="id" Type="Int16" />
            </SelectParameters>
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>



  Output:
logoblog

Thanks for reading Asp.Net DataSource Controls with Parameter

Previous
« Prev Post