获取商店数据的选中复选框和Ajax发布保存方法

时间:2017-11-27 05:55:41

标签: javascript asp.net ajax

我面临着如何获取所选复选框(单个或多个)的问题,并回发到从模态保存数据的方法。

复选框javascript的功能正在运行,到目前为止还不知道如何将它们放入ajax并发布。

点击复选框时,Ajax仍然无法获取复选框的数据!

这是ASPX的模态gridview代码:



<div class="modal-dialog">
 <div class="modal-body">
        <asp:UpdatePanel ID="updateGV" runat="server">
               <ContentTemplate>
            	<asp:Label CssClass="bolder" runat="server" ></asp:Label>
            	<input type="text" name="AddGroup" class="form-control" id="CreateGroup" onblur="GroupCheck()" />
            	 <br /><br />
            	  <asp:GridView runat="server" ID="gvLIST"  CssClass="table table-bordered"  
            					AutoGenerateColumns="false" >
            		  <Columns>
            			  <asp:TemplateField>
            				  <HeaderTemplate>
            					  <asp:CheckBox ID="gvCHECKALL" runat="server" onclick="allCHKBOX(this);"  />
            				  </HeaderTemplate>
            				  <ItemTemplate>
            					  <asp:CheckBox ID="gvCHECK" runat="server"  onclick="singleCHKBOX(this)" />
            				  </ItemTemplate>
            			  </asp:TemplateField>
            			  <asp:TemplateField HeaderText="ID" Visible="false">
            					<ItemTemplate>
            						<asp:Label ID="ID" runat ="server" Text='<%#Eval("ID") %>'  style="display:none"/> 
            					</ItemTemplate>
            			 </asp:TemplateField>
            			 <asp:BoundField HeaderText="Name" DataField="NME"/>
            		  </Columns>
            	  </asp:GridView>
               </ContentTemplate>
            </asp:UpdatePanel>
<button id="btnROUPSAVE" runat="server" disabled="disabled" onclick="btnGroupSaveClick()"  > 
   </div>
</div>
&#13;
&#13;
&#13;

&#13;
&#13;
<script type="text/javascript">
    function singleCHKBOX(chkBOX) {
        var IsChecked = chkBOX.checked;
        var Parent = document.getElementById('gvLIST');
        var chkALL;
        var items = Parent.getElementsByTagName('input');
        var unchkALL = true;
        for (i = 0; i < items.length; i++) {
            if (items[i].id.indexOf('gvCHECKALL') != -1) {
                chkALL = items[i];
                continue;
            }
            if (items[i].type == "checkbox" && items[i].checked == false) {
                unchkALL = false;
                break;
            }
        }
        chkALL.checked = unchkALL;
    }
	
	    function allCHKBOX(spanChk) {
        var IsChecked = spanChk.checked;
        var cbxAll = spanChk;
        var Parent = document.getElementById('gvLIST');
        var items = Parent.getElementsByTagName('input');
        for (i = 0; i < items.length; i++) {
            if (items[i].id != cbxAll.id && items[i].type == "checkbox") {
                items[i].checked = IsChecked;
            }
        }
    }
	
</script>
&#13;
&#13;
&#13;

&#13;
&#13;
function btnGroupSaveClick()
{
    var CreateGroup = $("#CreateGroup").val().trim();
    if (CreateGroup!= "" )
    {
        $.ajax({
            type: "POST",
            url: "test.aspx/CreateGroup",
            data: "{'CreateGroup':'" + CreateGroup+ "', 'gvCHECK':'" + gvCHECK+ "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
                    
            success: function (response) {
                alert(response.d);
            },
            failure: function (response) {
                alert(response.d);
            },
            error: function (response) {
                alert(response.d);
            }
                   
        });
    }
}
&#13;
&#13;
&#13;

0 个答案:

没有答案