Ajax调用asp.net后台方法功能实现

HTML

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>EIP資訊系統-會議室申請單管理</title>

    <script language="javascript" type="text/javascript">
        function btn_delete()
        {  
            if(confirm('确定要刪除嗎?')==true)
            {
                var select=document.getElementById("GridView1").getElementsByTagName("input");

                var no="";
                for(var i=1;i<select.length;i++)
                {
                    if(select[i].checked==true)
                    {
                        no=document.getElementById("GridView1").rows[i].cells[1].firstChild.innerText;
                        //調用后台方法
                        PageMethods.Hello(no,funReady,funError);

                    }
                }  
            }     
        }
        // result 就是后台方法返回的数据
        function funReady(result){
            alert("刪除成功!");
        }
        // err 就是后台方法返回的错误信息
        function funError(err){
            alert("Error:" + err._message);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server" method="post">
     <table cellspacing="0" cellpadding="0" width="100%" border="0" bgcolor="#00bfff" style="font-family: 細明體; font-size: 10pt;">
  <tr>
   <td>
    <table id="Table2" cellspacing="0" cellpadding="0" width="100%" border="0">
     <tr>
      <td width="100%">
                            <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
                            </asp:ScriptManager>
                            <font color= "#ff4500">會議室申請單</font>&nbsp;&nbsp;<img src="../IMG/xpLens.gif" alt=""/> 搜索关键字:
          <asp:DropDownList id="DropDownList1" runat="server">
              <asp:ListItem Value="0" Selected="True">--所有记录--</asp:ListItem>
              <asp:ListItem Value="1">單據類別</asp:ListItem>
              <asp:ListItem Value="doc_no">單據代號</asp:ListItem>
              <asp:ListItem Value="fact_no">申請廠別</asp:ListItem>
              <asp:ListItem Value="dept_no">申請單位</asp:ListItem>
              <asp:ListItem Value="employee_no">申請人</asp:ListItem>
              <asp:ListItem Value="3">審核狀態</asp:ListItem>
          </asp:DropDownList>&nbsp;&nbsp;
       <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>&nbsp;
       <asp:TextBox ID="txt_date" runat="server" CssClass="Wdate" οnfοcus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy/MM/dd'})" Width="80"></asp:TextBox>
       <asp:Button ID="btn_Search" runat="server" Text="查詢" />&nbsp;
       <asp:Button ID="btn_Add" runat="server" Text="新增" PostBackUrl="~/UI/DOC/Add_MeetingInfo.aspx"/>&nbsp;&nbsp;
       <input type="button" id="btn_del" value="刪除" οnclick="btn_delete();" />
       </td>
     </tr>
    </table>
   </td>
  </tr>
    </table>
     <table cellpadding="1" cellspacing="2" border="0" width="100%" style="font-family: 細明體; font-size: 12pt;">
         <tr>
             <td width="100%" >
                    <asp:GridView ID="GridView1" runat="server" CellPadding="0" Width="100%"
                        AutoGenerateColumns="False" AllowPaging="True"
                        PageSize="15" HeaderStyle-Font-Size="10.5">
                        <Columns>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:CheckBox ID="CheckBox1" runat="server" ToolTip='<%#Eval("doc_no") %>'/>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="申請單號" SortExpression="doc_no">
                                <ItemTemplate>
                                    <asp:Label ID="lab_no" runat="server" Text='<%#Eval("doc_no") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="申請單位" DataField="dept_no" />
                            <asp:BoundField HeaderText="會議主題" DataField="subject" />
                            <asp:BoundField HeaderText="申請日期" DataField="app_date" />
                            <asp:BoundField HeaderText="申請人" DataField="employee_no" />
                            <asp:BoundField HeaderText="會議日期" DataField="minfo_date" />
                            <asp:TemplateField HeaderText="狀態" SortExpression="state">
                                <ItemTemplate>
                                    <asp:DropDownList ID="drop_state" runat="server" Width="60px" Enabled="False" AutoPostBack="True" SelectedValue='<%# bind("state") %>'>
                                        <asp:ListItem Text="未審核" Value="0"></asp:ListItem>
                                        <asp:ListItem Text="送審中" Value="1"></asp:ListItem>
                                        <asp:ListItem Text="已審核" Value="2"></asp:ListItem>
                                        <asp:ListItem Text="已取消" Value="3"></asp:ListItem>
                                        <asp:ListItem Text="已確認" Value="4"></asp:ListItem>
                                    </asp:DropDownList>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <HeaderStyle Font-Size="10.5pt" />
                     </asp:GridView>
             </td>
         </tr>
    </table>
    </form>
</body>
</html>

 

Asp.Net .cs文件

 

//后台方法功实现刪除功能,傳申請單號

[System.Web.Services.WebMethod]
public static string Hello(string no)
    {
        string sql = "delete from doc_meeting where doc_no='" + no + "'";
        OracleDataAccess orcl = new OracleDataAccess();
        orcl.ExeSql(sql);
        return "刪除成功!";
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值