- <%@ 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>Using CancelSelectOnNullParameter property in SqlDataSource in asp.net</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <h2 style="color:Navy; font-style:italic;">SqlDataSource Example: using CancelSelectOnNullParameter Property</h2>
- <asp:SqlDataSource
- ID="SqlDataSource1"
- runat="server"
- ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
- SelectCommand="Select CategoryID, CategoryName From Categories"
- >
- </asp:SqlDataSource>
- <asp:DropDownList
- ID="DropDownList1"
- runat="server"
- DataSourceID="SqlDataSource1"
- DataValueField="CategoryID"
- DataTextField="CategoryName"
- AppendDataBoundItems="true"
- AutoPostBack="true"
- >
- <asp:ListItem Text="All" Value=""></asp:ListItem>
- </asp:DropDownList>
- <asp:SqlDataSource
- ID="SqlDataSource2"
- runat="server"
- ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
- SelectCommand="Select ProductID, ProductName, QuantityPerUnit, UnitPrice From Products Where CategoryID=IsNull(@CategoryID, CategoryID)"
- SelectCommandType="Text"
- CancelSelectOnNullParameter="false"
- >
- <SelectParameters>
- <asp:ControlParameter
- Name="CategoryID"
- ControlID="DropDownList1"
- PropertyName="SelectedValue"
- ConvertEmptyStringToNull="true"
- />
- </SelectParameters>
- </asp:SqlDataSource>
- <asp:GridView
- ID="GridView1"
- runat="server"
- DataSourceID="SqlDataSource2"
- AutoGenerateColumns="true"
- AllowPaging="true"
- PageSize="10"
- BorderColor="Snow"
- Font-Names="Comic Sans MS"
- Width="650"
- >
- <HeaderStyle
- BackColor="DarkGoldenrod"
- BorderColor="PeachPuff"
- ForeColor="Snow"
- Height="45"/>
- <RowStyle
- BackColor="Chocolate"
- ForeColor="Snow"
- Font-Italic="true" />
- <PagerStyle
- Height="45"
- HorizontalAlign="Right"
- BackColor="OrangeRed"
- Font-Bold="true"
- Font-Size="X-Large"
- ForeColor="Snow"
- />
- <PagerSettings Mode="Numeric" />
- </asp:GridView>
- </div>
- </form>
- </body>
- </html>
mandag den 8. juni 2015
Sql select statement where is empty null
Abonner på:
Kommentarer (Atom)