SqlDataSource 调用带参数的存储过程

 

<%@ Page Language="VB" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<script runat="server">

 

    Protected Sub btnShow_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        Me.gvParam.DataBind()

    End Sub

</script>

 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>sqlDataSource执行带参数的存储过程</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <%-- gvParam --%>

        <asp:GridView ID="gvParam" Caption ="Param" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="sqlDsParam">

            <Columns>

                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />

                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />

                <asp:BoundField DataField="Author" HeaderText="Author" SortExpression="Author" />

                <asp:BoundField DataField="Descrip" HeaderText="Descrip" SortExpression="Descrip" />

                <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />

                <asp:BoundField DataField="Size" HeaderText="Size" SortExpression="Size" />

                <asp:CommandField ShowDeleteButton="True" />

            </Columns>

        </asp:GridView>

       

        <asp:TextBox ID="txtID" runat="server" Width="67px" Text ="1" />

        <asp:Button ID="btnShow" runat="server" OnClick="btnShow_Click" Text="Show" />

       

        <%-- gvAll --%>

        <asp:GridView ID="gvAll" Caption ="gvAll" runat="server" AutoGenerateColumns="False" DataSourceID="sqlDsAll">

            <Columns>

                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />

                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />

                <asp:BoundField DataField="Author" HeaderText="Author" SortExpression="Author" />

                <asp:BoundField DataField="Descrip" HeaderText="Descrip" SortExpression="Descrip" />

                <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />

                <asp:BoundField DataField="Size" HeaderText="Size" SortExpression="Size" />

            </Columns>

        </asp:GridView>

        <%-- DataSource: sqlDsAll --%>

        <asp:SqlDataSource ID="sqlDsAll" runat="server" ConnectionString="<%$ ConnectionStrings:picDataBaseConnectionString1 %>"

            SelectCommand="SELECT * FROM [picTable]"></asp:SqlDataSource>

        <%-- DataSource: sqlDsParam --%>

        <asp:SqlDataSourceID="sqlDsParam"runat="server"ConnectionString="<%$ConnectionStrings:picDataBaseConnectionString1 %>"

        DeleteCommand="DeleteByID" DeleteCommandType="StoredProcedure"

        SelectCommand="StoredProcedureWithParam" SelectCommandType="StoredProcedure">

            <DeleteParameters>

                <asp:ControlParameter ControlID ="gvParam" Name ="id" PropertyName ="SelectedValue" Type ="int32" />

            </DeleteParameters>

            <SelectParameters>

                <asp:ControlParameter ControlID="txtID" Name="pId" PropertyName="Text" Type="Int32" />

            </SelectParameters>

        </asp:SqlDataSource>

    </div>

    </form>

</body>

</html>


转载地址:http://microphoenix.spaces.live.com/blog/cns!cae32c6a59c74431!268.entry

posted @ 2007-01-09 09:32  M'  阅读(2636)  评论(0编辑  收藏  举报