本文介绍了如何提醒用户是否在转发器内选中了复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我需要在选中复选框时提醒用户。 我在转发器内使用了复选框。 我试过这样的.. I need alert the user when the check box is checked or not.I have used check box inside the repeater.I have tried like this.. <script type="text/javascript"> function validate() { var count = 0; var repeater = document.getElementById("check"); var checkBoxes = repeater.getElementsByTagName("input"); for (var i = 0; i <checkBoxes.length; i++) { if (checkBoxes[i].type == "checkbox" && checkBoxes[i].checked) { count++; } } if (count == 0) { alert("Kindly select the feedback to delete"); return false; } else { confirm("Are you sure you want to delete?"); } }</script> ><asp:Repeater ID="feedback" runat="server" onitemcommand="RepterDetails_ItemCommand"><ItemTemplate><table style="border-top:1px dotted #3b5998; width:650px" id="check"><tr><td><asp:CheckBox ID="chk" runat="server" EnableViewState="true" /></td></tr></table></ItemTemplate><FooterTemplate><tr><td> <table width="650px" style="background-color:White;height:10px"> <td align="center"> <asp:Button ID="lnkDelSelected" ForeColor="white" runat="server" Text="Delete Selected" onclick="LinkButton1_Click" OnClientClick="return (validate());" CssClass="item_button"></asp:Button> </td></tr> </Table> </td> </tr> </FooterTemplate></asp:Repeater> 但是它无法正常工作。 如果在转发器中选中了第一个复选框,则显示正确的警告消息。 如果在转发器中选中第一个和任何其他复选框,则显示正确的警告消息 问题是, 如果我选择剩余的复选框,而不选择第一个复选框, 不接受那个条件复选框。检查 请建议我这个条件。 提前感谢but its not working correctly.if the first check box is checked in repeater, its showing correct alert message.if the first and any other checkbox is checked in repeater, its showing correct alert messagethe problem is,if i have select remaining checkboxes, without selecting first check box,its not taking that condition checkbox.checkedkindly suggest me the condition.thanks in advance推荐答案 <asp:Repeater ID="rptUsers" runat="server"> <HeaderTemplate> <table id="check" border="1"> <tr> <th>Select</th> <th>Name </th> <th>Country </th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <asp:CheckBox ID="chkbox" Text="" runat="server" /> </td> <td> <%#Eval("Name") %> </td> <td> <%#Eval("Country") %> </td> </tr> </ItemTemplate> <FooterTemplate> <tr> <td> <table style="background-color: yellow; height: 10px"> <tr> <td> <asp:Button ID="btn" ForeColor="Green" runat="server" OnClick="btn_Click" Text="Delete Selected" OnClientClick="return (Validate());"></asp:Button> </td> </tr> </table> </td> </tr> </table> </FooterTemplate> </asp:Repeater> 绑定转发器和按钮点击后面的代码: Code behind to bind repeater and button click :protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //bind repeater with dummy data rptUsers.DataSource = BindGrid(); rptUsers.DataBind(); } } //btn click example protected void btn_Click(object sender, EventArgs e) { Response.Write("Post back done"); } //Dummy data to bind repeater private DataTable BindGrid() { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)), new DataColumn("Name", typeof(string)), new DataColumn("Country",typeof(string)) }); dt.Rows.Add(1, "Rajesh Biswas", "India"); dt.Rows.Add(2, "Johny Depp", "US"); dt.Rows.Add(3, "Mad Hatter", "US"); dt.Rows.Add(4, "Willy Bonka", "US"); return dt; } Javascript代码: Javascript code :<script type="text/javascript"> function Validate() { var count = 0; var repeater = document.getElementById("check"); var checkBoxes = repeater.getElementsByTagName("input"); for (var i = 0; i < checkBoxes.length; i++) { if (checkBoxes[i].type == "checkbox" && checkBoxes[i].checked) { count++; } } if (count == 0) { alert("Kindly select the feedback to delete"); return false; } else { return confirm("Are you sure you want to delete?"); } //Using Jquery //var chkboxrowcount = 这篇关于如何提醒用户是否在转发器内选中了复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-30 12:38