单击批准按钮时无响应

时间:2013-09-30 19:27:16

标签: c# asp.net

我有一个项目,这个文件管理系统在这个itry,以提供/拒绝文件和fr 我创建sp以批准和拒绝文档

ALTER procedure [dbo].[sprejectapprove]
        @UserID int,
        @DocID int,
        @ApproveType nvarchar(50)
as
    Insert into Approval(UserID,DocID,ApproveType)
    values(@UserID,@DocID,@ApproveType)

批准:

 ALTER procedure [dbo].[spinsertapprove]
     @UserID int,
     @DocID int,
     @ApproveType nvarchar(50)
 as
     Insert into Approval(UserID,DocID,ApproveType)
     values(@UserID,@DocID,@ApproveType)

和代码是

protected void GrdFileApprove_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "_Approve")
    {
        //using (SqlConnection con = DataAccess.GetConnected())
        using (SqlConnection con = 
                 new SqlConnection(ConfigurationManager.ConnectionStrings["mydms"].ConnectionString))
        {
            try
            {
                int rowindex = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = (GridViewRow)     

            ((Control)e.CommandSource).NamingContainer;
                LinkButton Prove_Button =   
               (LinkButton)row.FindControl("BtnApprove");
                SqlCommand cmd = new SqlCommand("spinsertapprove", con);
                cmd.CommandType = CommandType.StoredProcedure;
                int result = cmd.ExecuteNonQuery();
                if (result != 0)
                {
                    GrdFileApprove.DataBind();
                }
            }

            catch 
            {
                apfi.Text = "Not Approve";
            }
            finally
            {
                con.Close();
            }
        }
    }


    else if (e.CommandName == "_Reject")
    {
        using (SqlConnection con = 
                    new SqlConnection(ConfigurationManager.ConnectionStrings["mydms"].ConnectionString))
        {
            try
            {
                int rowindex = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = (GridViewRow)
                ((Control)e.CommandSource).NamingContainer;
                LinkButton Prove_Button = (LinkButton)row.FindControl("Button1");
                SqlCommand cmd = new SqlCommand("sprejectapprove", con);
                cmd.CommandType = CommandType.StoredProcedure;
                int result = cmd.ExecuteNonQuery();
                if (result != 0)
                {
                    GrdFileApprove.DataBind();
                }
            }

            catch 
            {
                apfi.Text = "Rejct";
            }
            finally
            {
                con.Close();
            }
        }
    }
}

当我调试代码并单击批准或拒绝按钮时,它无法继续进行并且也没有向我显示任何错误

这是grdiview

<div>
        <asp:ScriptManager ID="ScriptManager1" runat="server"/>
         <asp:UpdatePanel runat="server" ID="UPanle" 
            ondatabinding="UPanle_DataBinding_Click">
            <ContentTemplate>
           <asp:GridView ID="GrdFileApprove" runat="server" 
            AutoGenerateColumns="false" 
                onrowcommand="GrdFileApprove_RowCommand" 
                onselectedindexchanged="GrdFileApprove_SelectedIndexChanged">
               <Columns>
                   <asp:TemplateField HeaderText="S no">
                       <ItemTemplate>
                           <%# Container.DataItemIndex+1 %>
                           <asp:HiddenField runat="server" ID="HdnFileID" Value='<%#
                       Eval("DocID") %>' />
                       </ItemTemplate>
                   </asp:TemplateField>
                   <asp:BoundField DataField="DocID" HeaderText="DocumentID"  />
                   <asp:BoundField DataField="DocName" HeaderText="DocName"  />
                   <asp:BoundField DataField="Uploadfile" HeaderText="File Name" />
                   <asp:BoundField DataField="DocType" HeaderText="Document" />
                   <asp:BoundField DataField="DepType" HeaderText="Department" />
                   <asp:TemplateField HeaderText="S no">
                       <ItemTemplate>
                           <asp:Button runat="server" Id="BtnApprove" 
                        CommandName="_Approve" 
                                CommandArgument='<%# Eval("DocID") %>' 
                            Text="Aprrove"   />
                           <asp:Button runat="server" Id="Button1"
                           CommandName="_Reject" 
                                CommandArgument='<%# Eval("DocID") %>' Text="Reject" />
                       </ItemTemplate>
                   </asp:TemplateField>
               </Columns>
           </asp:GridView>
       </ContentTemplate>


        </asp:UpdatePanel> 

</div>

1 个答案:

答案 0 :(得分:0)

您没有向SQL调用添加任何参数值,因此可能根本没有调用存储过程,因为您没有定义的任何默认值。

您需要在调用之前为每个参数添加以下内容:

myCommand.Parameters.AddWithValue("@UserID", userId);
myCommand.Parameters.AddWithValue("@DocID", docId);
myCommand.Parameters.AddWithValue("@ApproveType", "Approve");

最后一个是:

myCommand.Parameters.AddWithValue("@ApproveType", "Reject");

拒绝案件。

这些值需要从存储的位置读取,而不是当然是硬编码。