利用存储过程,实现GridView中的删除

cs文件中       

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            SqlDataSource1.DeleteParameters["InfoID"].DefaultValue = Convert.ToString(GridView1.DataKeys[e.RowIndex].Value);

cs文件中       

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            SqlDataSource1.DeleteParameters["InfoID"].DefaultValue = Convert.ToString(GridView1.DataKeys[e.RowIndex].Value);
;        }

 

.aspx文件中

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="id" 
                AutoGenerateColumns="False"  HorizontalAlign="Center" Width="100%"
        CellPadding="4" ForeColor="#333333"
            GridLines="None" 
        onrowdeleting="GridView1_RowDeleting">

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="GetRecordFromPages"
        SelectCommandType="StoredProcedure" DeleteCommand="DeleteUserInfoBySelf"
        DeleteCommandType="StoredProcedure" OldValuesParameterFormatString="InfoID">

        <DeleteParameters>            
            <asp:Parameter Name="InfoID" Type="Int32" />
            <asp:Parameter Name="UserID" Type="Int32" />           
        </DeleteParameters>

发表评论

电子邮件地址不会被公开。 必填项已用*标注