2013-09-30 182 views
0

我有一个项目,该项目是文件同治系统在这itry到apporve /拒绝文件和FR这 我创造批准和拒绝文档当点击确认按钮

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

SP批准无响应:

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

你可以在你的GridView声明的地方显示ASPX标记吗? –

+0

你能够在调试模式下运行吗?如果你在RowCommand处理程序中设置了一个断点,它是否被触发? e.CommandName的价值是什么? – lincolnk

+0

是的,我设置了一个断点,但当我调试并按f11然后它仍然无法进行 – user2832406

回答

0

你不加入任何参数值,以您的SQL调用,因此存储过程可能根本不会被调用,因为您没有定义任何默认值。

你需要调用之前添加每个参数如下:

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

与最后一个是:

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

为拒绝的情况。

这些值需要从存储的地方读取,而不是被硬编码。

+0

它还没有给我任何回应时我点击批准或拒绝按钮 – user2832406

+0

@ user2832406 - 检查调试器是否将正确的值传递给参数。修改存储过程,以便它可以执行其他操作,以便确认它实际上是否已被调用。使用SQL跟踪来验证存储过程是否被调用。 – ChrisF