2017-03-01 20 views
0

我有一个自定义控件列表视图与复选框。如果用户检查一个列表项,代码将按原样流动。如果用户选中多个复选框,它将显示一条警告消息“计划在同一天的多个时间段将覆盖文件”,并显示确定并取消。确认框可以取消C#web应用程序

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

我已经尝试了很多不同的方式使用Javascript。它没有解决。请帮忙。

而且我不能使用OnclientClick/OnClick,因为我使用相同的列表视图来绑定不同的数据源。只有在具有多个检查的计划时间值的列表视图时,才需要弹出警报消息。如果条件为,请在下面的C#代码中找到

代码隐藏:

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天的支出。

请帮忙!谢谢

+0

看看[jQuery对话框](https://jqueryui.com/dialog/#modal-confirmation)。它有确认/取消选项。 – VDWWD

回答

0

你可以有一个布尔值,说:“blnNeedpopup”,只有当你需要弹出时才将它设置为true。

虽然在.DataBound方法中将数据源绑定到列表视图,但只有当blnNeedpopup为TRUE时,才可以将ONCLICK添加到checkBox元素。所以哟会根据你的情况得到这些弹出窗口。

另外,当用户点击确定或取消您不需要做回发,而是可以在简单的JQuery函数中处理。