ASP.NET SqlDataSource - How to handle null value parameters

Handle null value parameters in SqlDataSource
GridView.aspx

<%@ Page Language="C#" AutoEventWireup="true" %>

<!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 id="Head1" runat="server">
    <title>How to handle null value parameters in SqlDataSource in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy; font-style:italic;">SqlDataSource Control Example: handle null value parameters</h2>
        <asp:Label 
            ID="Label1" 
            runat="server"
            Font-Bold="true"
            ForeColor="DodgerBlue"
            Font-Size="Larger"
            Text="Categories"
            >
        </asp:Label>
        <asp:DropDownList 
            ID="DropDownList1"
            runat="server"
            BackColor="DodgerBlue"
            ForeColor="Snow"
            Font-Bold="true"
            Font-Italic="true"
            DataSourceID="SqlDataSource1"
            DataTextField="CategoryName"
            DataValueField="CategoryID"
            AppendDataBoundItems="true"
            AutoPostBack="true"
            >
            <asp:ListItem Value="">Show All</asp:ListItem>
        </asp:DropDownList>
        <br /><br />
        <asp:SqlDataSource 
            ID="SqlDataSource1"
            runat="server"
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="Select CategoryID, CategoryName From Categories"
            >
        </asp:SqlDataSource>
        <asp:SqlDataSource 
            ID="SqlDataSource2"
            runat="server"
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="Select ProductID, ProductName, UnitPrice From Products Where CategoryID= IsNull(@CategoryID, CategoryID)"
            CancelSelectOnNullParameter="false"
            >
            <SelectParameters>
                <asp:ControlParameter 
                    ControlID="DropDownList1" 
                    PropertyName="SelectedValue"
                    Name="CategoryID"
                    ConvertEmptyStringToNull="true"
                    />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:GridView 
            ID="GridView1"
            runat="server"
            DataSourceID="SqlDataSource2"
            AllowPaging="true"
            BackColor="Crimson"
            ForeColor="Snow"
            BorderColor="Snow"
            >
            <HeaderStyle BackColor="DodgerBlue" ForeColor="Snow" />
            <Columns>
                <asp:BoundField DataField="ProductID" HeaderText="Product ID" ReadOnly="true" />
                <asp:BoundField DataField="Productname" HeaderText="Product Name" />
                <asp:BoundField DataField="UnitPrice" HeaderText="Unit Price" />
            </Columns>        
        </asp:GridView>
                
    </div>
    </form>
</body>
</html>
More asp.net examples