确认框可以取消C#网络应用程序

时间:2017-03-01 19:09:50

标签: javascript c# jquery asp.net listview

我有一个带复选框的自定义控件列表视图。如果用户检查一个列表项,代码将按原样流动。如果用户检查多个复选框,它将显示一条警告消息"预定同一天的多个时隙将覆盖该文件"好的和取消。

如果用户单击“确定”,他将允许并使用功能。如果他点击取消,它应该返回并取消选中他检查的第二个值。

我通过使用Javascript尝试了很多不同的方法。没有一个成功。请帮助。

我无法使用OnclientClick / OnClick,因为我使用相同的列表视图来绑定不同的数据源。我需要仅在具有多个检查的计划时间值的列表视图时弹出警报消息。请在下面的C#代码中找到 if condition

代码隐藏:

 protected void chkCheck_CheckedChanged(object sender, EventArgs e)
    {

        CheckBox chkCheck = (CheckBox)sender;
        ListViewItem item = (ListViewItem)chkCheck.NamingContainer;
        ListViewDataItem dataItem = (ListViewDataItem)item;
        if (lookupMstVal == "ScheduledTime." && lbCheckedIdList.Items.Count > 0 && chkCheck.Checked)
        {
            //To do
        }
          string lookupId = lvLookup.DataKeys[dataItem.DisplayIndex].Value.ToString();
            if (chkCheck.Checked)
                lbCheckedIdList.Items.Add(lookupId);
            else
                lbCheckedIdList.Items.Remove(lookupId);
            hdfLookupId.Value = "";
            foreach (ListItem itm in lbCheckedIdList.Items)
            {
                hdfLookupId.Value += (hdfLookupId.Value == "" ? "" : ",") + itm.Value;
            }
            postbackFlag = true;
     }

.axcs

<asp:ListView ID="lvLookup" runat="server" GroupPlaceholderID="groupPlaceHolder1"
                ItemPlaceholderID="itemPlaceHolder1" OnPagePropertiesChanging="lvLookup_PagePropertiesChanging" DataKeyNames="DCLookup_Id">
                <LayoutTemplate>

                    <table style="width: 100%">

                        <tr>
                            <th></th>
                            <%-- <th id="colLookupId">Lookup Id</th>--%>

                            <th>Lookup Values
                            <asp:Label ID="lblTimeZone" runat="server" Text=""></asp:Label></th>
                        </tr>
                        <asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder>
                        <tr>
                            <td colspan="3" class="ui-helper-center">
                                <asp:DataPager ID="DataPager1" runat="server" PagedControlID="lvLookup" PageSize="10">
                                    <Fields>
                                        <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="true" ShowPreviousPageButton="true"
                                            FirstPageText="<span style='font-size:16px;'><b><<</b></span>" PreviousPageText="<span style='font-size:14px;'><b><</b></span>" ShowNextPageButton="false" />
                                        <asp:NumericPagerField ButtonType="Link" />
                                        <asp:NextPreviousPagerField ButtonType="Link" ShowNextPageButton="true" ShowLastPageButton="true"
                                            ShowPreviousPageButton="false" LastPageText="<span style='font-size:16px;'><b>>></b></span>" NextPageText="<span style='font-size:14px;'><b>></b></span>" />
                                    </Fields>
                                </asp:DataPager>
                            </td>
                        </tr>
                    </table>
                </LayoutTemplate>
                <GroupTemplate>
                    <tr>
                        <asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder>
                    </tr>
                </GroupTemplate>
                <ItemTemplate>
                    <td>
                        <asp:CheckBox ClientIDMode="AutoID" ID="chkCheck" ToolTip='<%# Eval("DCLookup_Id") %>' runat="server" AutoPostBack="true"
                            OnCheckedChanged="chkCheck_CheckedChanged"/>
                    </td>
                    <%--<td id="colDCLookupId">
                    <%# Eval("DCLookup_Id") %>
                </td>--%>
                    <td>
                        <%# Eval("DCLookup_Value") %>
                    </td>
                </ItemTemplate>
                <EmptyDataTemplate>
                    No Records
                </EmptyDataTemplate>
            </asp:ListView>

对某些人来说这可能很容易,但对我来说,我已经花了2天时间。

请帮忙!谢谢

1 个答案:

答案 0 :(得分:0)

你可以有一个布尔值,说&#34; blnNeedpopup&#34;并且仅在需要弹出窗口时将其设置为true。

虽然在.DataBound方法中将数据源绑定到listview,但只有当blnNeedpopup为TRUE时,才能将ONCLICK添加到checkBox元素。所以你只能根据自己的条件获得这些弹出窗口。

此外,当用户单击“确定”或“取消”时,您不需要进行回发,而是可以处理简单的JQuery功能。