CheckBoxList –成功,RadioButtonList –失败

时间:2018-11-04 15:26:38

标签: c# asp.net checkboxlist radiobuttonlist modalpopupextender

在与AjaxToolKit中的不同ModalPopupExtenders关联的不同面板中,同一个.aspx文件中有一个CheckBoxList和四个RadioButtonLists。我不处理他们的SelectedIndexChanged事件。列表元素的状态在按钮事件处理程序中进行了测试;这些按钮也位于这些面板中。 CheckBoxList元素(在'cblFlter'中)的状态会传递到带有复选框列表的面板中的OK按钮的处理程序。 RadioButtonLists元素的状态(从'obl0'到'obl3')不会传递到带有单选按钮列表的面板中的OK按钮的处理程序:调试c#代码时,所有这四个代码始终具有其无论选择哪个单选按钮,无论我在单击“确定”之前单击了哪个单选按钮,并且无论为标记中的每个单选按钮列表设置了不同的“选择”属性,都是如此。

以下是.aspx文件的部分列表:

<%@ Page Title="List of Expenses" Language="C#" MasterPageFile="~/mTSoar.Master" AutoEventWireup="true" CodeBehind="Expenses.aspx.cs"
Inherits="TSoar.Accounting.FinDetails.ExpVendAP.Expenses" %>

<asp:Content ID="HeaderContent" ContentPlaceHolderID="ContentPlaceHolderHeader" runat="server">
<asp:Label runat="server" Text="Accounting - Bookkeeping - Expenses, Vendors, Accounts Payable - Expenses" Font-Italic="true" />
</asp:Content>

<asp:Content ID="MainContent" ContentPlaceHolderID="ContentPlaceHolderMain" runat="server">
<a href="XactExpense.aspx">Create New Expense Record</a>
.
.
.
<div id="ModPopExtFiltering">
    <asp:LinkButton ID="LinkButton2" runat="server" Text="T" CssClass="displayNone" />
    <ajaxToolkit:ModalPopupExtender ID="ModPopExtFilter" runat="server"
        TargetControlID="LinkButton2" PopupControlID="MPE_PanelFilter"
        BackgroundCssClass="background" />
    <asp:Panel ID="MPE_PanelFilter" runat="server" CssClass="popup" style="display:none;" HorizontalAlign="Center">
        Display those transactions with a status that is checked:
        <p>
            <asp:CheckBoxList ID="cblFilter" runat="server" RepeatDirection="Vertical" RepeatLayout="UnorderedList" >
                <asp:ListItem>Active</asp:ListItem>
                <asp:ListItem>Voided</asp:ListItem>
                <asp:ListItem>Deleted</asp:ListItem>
                <asp:ListItem>Template</asp:ListItem>
            </asp:CheckBoxList>
        </p>
        <p> <asp:Button ID="pbFilterOK" runat="server" Text="OK" OnClick="pbFilterOKCancel_Click" />&nbsp;&nbsp;
            <asp:Button ID="pbFilterCancel" runat="server" Text="Cancel" OnClick="pbFilterOKCancel_Click" />
        </p>
    </asp:Panel>
</div>

<div id="ModPopExtSorting">
    <asp:LinkButton ID="LinkButton3" runat="server" Text="T" CssClass="displayNone" />
    <ajaxToolkit:ModalPopupExtender ID="ModPopExtSort" runat="server"
        TargetControlID="LinkButton3" PopupControlID="MPE_PanelSort"
        BackgroundCssClass="background" />
    <asp:Panel ID="MPE_PanelSort" runat="server" CssClass="popup" style="display:none;" HorizontalAlign="Center">
        <table style="align-self:center">
            <tr>
                <td</td><td></td><td></td>
                <td>Sort Priority</td>
            </tr>
            <tr>
                <th></th><th>&nbsp;</th>
                <th><asp:Label runat="server" Text="1&nbsp;2&nbsp;3&nbsp;4" Font-Size="Medium" /></th>
            </tr>
            <tr>
                <td>Date</td><td></td>
                <td><asp:RadioButtonList ID="obl0" runat="server" RepeatColumns="4" RepeatDirection="Horizontal" RepeatLayout="Table"
                    EnableViewState="true" ViewStateMode="Enabled">
                        <asp:ListItem> &nbsp; </asp:ListItem>
                        <asp:ListItem> &nbsp; </asp:ListItem>
                        <asp:ListItem> &nbsp; </asp:ListItem>
                        <asp:ListItem Selected="True"> &nbsp; </asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            <tr>
                <td>Vendor</td><td></td>
                <td><asp:RadioButtonList ID="obl1" runat="server" RepeatColumns="4" RepeatDirection="Horizontal" RepeatLayout="Table"
                    EnableViewState="true" ViewStateMode="Enabled">
                        <asp:ListItem> &nbsp; </asp:ListItem>
                        <asp:ListItem> &nbsp; </asp:ListItem>
                        <asp:ListItem Selected="True"> &nbsp; </asp:ListItem>
                        <asp:ListItem> &nbsp; </asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            <tr>
                <td>Status</td><td></td>
                <td><asp:RadioButtonList ID="obl2" runat="server" RepeatColumns="4" RepeatDirection="Horizontal" RepeatLayout="Table"
                    EnableViewState="true" ViewStateMode="Enabled">
                        <asp:ListItem> &nbsp; </asp:ListItem>
                        <asp:ListItem Selected="True"> &nbsp; </asp:ListItem>
                        <asp:ListItem> &nbsp; </asp:ListItem>
                        <asp:ListItem> &nbsp; </asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            <tr>
                <td>Amount</td><td></td>
                <td><asp:RadioButtonList ID="obl3" runat="server" RepeatColumns="4" RepeatDirection="Horizontal" RepeatLayout="Table"
                    EnableViewState="true" ViewStateMode="Enabled">
                        <asp:ListItem Selected="True"> &nbsp; </asp:ListItem>
                        <asp:ListItem> &nbsp; </asp:ListItem>
                        <asp:ListItem> &nbsp; </asp:ListItem>
                        <asp:ListItem> &nbsp; </asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
        </table>
        <p> <asp:Button ID="pbSortOK" runat="server" Text="OK" OnClick="pbSortOKCancel_Click" />&nbsp;&nbsp;
            <asp:Button ID="pbSortCancel" runat="server" Text="Cancel" OnClick="pbSortOKCancel_Click" />
        </p>
    </asp:Panel>
</div>
.
.
.

这是.aspx.cs文件的部分列表:

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TSoar.DB;

namespace TSoar.Accounting.FinDetails.ExpVendAP
{
    public partial class Expenses : System.Web.UI.Page
    {
.
.
.

        protected void pbFilter_Click(object sender, EventArgs e)
        {
            DataTable dtTFilter = AccountProfile.CurrentUser.XactFilterSettings;
            for (int i = 0; i < 4; i++)
            {
                cblFilter.Items[i].Selected = (bool)dtTFilter.Rows[i]["bFilter"];
            }
            ModPopExtFilter.Show();
        }

        protected void pbFilterOKCancel_Click(object sender, EventArgs e)
        {
            Button pb = (Button)sender;
            switch (pb.ID)
            {
                case "pbFilterOK":
                    DataTable dtTFilter = AccountProfile.CurrentUser.XactFilterSettings;
                    for (int i = 0; i < 4; i++)
                    {
                        dtTFilter.Rows[i]["bFilter"] = cblFilter.Items[i].Selected;
                    }
                    AccountProfile.CurrentUser.XactFilterSettings = dtTFilter;
                    DisplayGrid();
                    break;
                default:
                    break;
            }
        }

        protected void pbSort_Click(object sender, EventArgs e)
        {
            RadioButtonList[] obla = new RadioButtonList[4];
            obla[0] = obl0;
            obla[1] = obl1;
            obla[2] = obl2;
            obla[3] = obl3;
            DataTable dtTSort = AccountProfile.CurrentUser.XactSortSettings;
            int rowIndex = 0;
            foreach(DataRow dr in dtTSort.Rows)
            {
                obla[rowIndex].ClearSelection();
                obla[rowIndex].Items[(int)dr["SortOrder"] - 1].Selected = true;
                rowIndex++;
            }
            ModPopExtSort.Show();
        }


        protected void pbSortOKCancel_Click(object sender, EventArgs e)
        {
            Button pb = (Button)sender;
            switch (pb.ID)
            {
                case "pbSortOK":
                    RadioButtonList[] obla = new RadioButtonList[4];
                    obla[0] = obl0;
                    obla[1] = obl1;
                    obla[2] = obl2;
                    obla[3] = obl3;
                    int iSum = 0;
                    foreach (XactSort.eSortBy es in Enum.GetValues(typeof(XactSort.eSortBy)))
                    {
                        for (int j = 1; j < 5; j++)
                        {
                            if (obla[(int)es].Items[j-1].Selected)
                            {
                                iSum += j * (int)(Math.Pow(10.0, j - 1) + 0.1);
                            }
                        }
                    }
                    if (iSum != 4321)
                    {
                        ProcessPopupException(new Global.excToPopup("Invalid Sort Priorities - each of Date, Vendor, Status, and Amount " +
                            "must be assigned a different sort priority between 1 and 4. [Checksum=" + iSum.ToString() + "]"));
                    }
                    else
                    {
                        DataTable dtTSort = AccountProfile.CurrentUser.XactSortSettings;
                        foreach(XactSort.eSortBy es in Enum.GetValues(typeof(XactSort.eSortBy)))
                        {
                            for (int j = 1; j < 5; j++)
                            {
                                if (obla[(int)es].Items[j-1].Selected)
                                {
                                    dtTSort.Rows[(int)es]["SortOrder"] = j;
                                }
                            }
                        }
                        AccountProfile.CurrentUser.XactSortSettings = dtTSort;
                        DisplayGrid();
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
.
.
.

您需要更多信息来帮助我解决这一问题吗?

1 个答案:

答案 0 :(得分:0)

如马丁·乌尔里希(Martin Ullrich)的建议,通过在每个RadioButtonList ListItem中添加“ Value”属性来解决问题,就像这样(一个RadioButtonList中的每个ListItem的value属性必须不同):

import React, { Component, PropTypes } from 'react';
import './App.css';
import FirstPage from './mainPage.jpg';
import SecondPage from './secondPage.jpg';
import OtherPage from './otherPage.jpg';
import Placeholder from './placeholder.jpg';

  var pdfConverter = require('jspdf');
  const image2base64 = require('image-to-base64');
class App extends Component {
  constructor(props) {
  super(props);
    this.state = {
      Name:"Jimmy Kaler",
      firstPage:'',
      secondPage:'',
      otherPage:'',
      placeholder:''
    }
  };
  firstPage = () =>{
    image2base64(FirstPage)
        .then(
            (response) => {
                this.setState({firstPage:response});
            }
        );
  }
  secondPage = () =>{
    image2base64(SecondPage)
        .then(
            (response) => {
                this.setState({secondPage:response});
            }
        );
  }
  otherPage = () => {
    image2base64(OtherPage)
        .then(
            (response) => {
                this.setState({otherPage:response})
            }
        )
  }

  placeholderImage = () => {
    image2base64(Placeholder)
        .then(
            (response) => {
                this.setState({placeholder:response})
            }
        )
  }
  componentWillMount(){
    this.firstPage();
    this.secondPage();
    this.otherPage();
    this.placeholderImage();
  }


  printDocument = () => {
    const {firstPage,secondPage,otherPage,placeholder} = this.state;
              const doc = new pdfConverter('p','pt','a4');
            var fPage = 'data:image/jpeg;base64,'+firstPage;
            var sPage = 'data:image/jpeg;base64,'+secondPage;
            var oPage = 'data:image/jpeg;base64,'+otherPage;
            var pImage = 'data:image/jpeg;base64,'+placeholder;
               doc.setFontSize(14);
               doc.setTextColor(40);
               doc.setFontStyle('normal');
               doc.addImage(fPage, 'JPEG', 5, 0, 590, 842);
               doc.addImage(pImage, 'JPEG', 60, 90, 210, 130);
               doc.setFontSize(14);
               doc.setFont("arial");
               doc.setFontType("normal");
               doc.text(40, 240, 'Production Name:');

               doc.setFontSize(12);
               doc.setFont("arial");
               doc.setFontType("normal");
               var pDescription = "Here will be our production Name.";
               var splitDesc = doc.splitTextToSize(pDescription, 260);
               doc.text(40, 260, splitDesc);

               doc.setFontSize(14);
               doc.setFont("arial");
               doc.setFontType("normal");
               doc.text(40, 370, 'Deadline: 10/11/2017');

               doc.setFontSize(14);
               doc.setFont("arial");
               doc.setFontType("normal");
               doc.text(40, 400, 'Category: My Category');

               doc.setFontSize(14);
               doc.setFont("arial");
               doc.setFontType("normal");
               doc.text(40, 430, 'Total Duration: 5:00');

               doc.setFontSize(14);
               doc.setFont("arial");
               doc.setFontType("normal");
               doc.text(40, 460, 'Objective:');

               doc.setFontSize(12);
               doc.setFont("arial");
               doc.setFontType("normal");
               var oDescription = "Here will be our Objective description. Here will be our Objective description.";
               var splitObj = doc.splitTextToSize(oDescription, 260);
               doc.text(40, 480, splitObj);

               doc.setFontSize(14);
               doc.setFont("arial");
               doc.setFontType("normal");
               doc.text(40, 530, 'Target Audience:');

               doc.setFontSize(12);
               doc.setFont("arial");
               doc.setFontType("normal");
               var tDescription = "Here will be our production description. Here will be our production description.";
               var splitTarg = doc.splitTextToSize(tDescription, 260);
               doc.text(40, 550, splitTarg);

                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("normal");
                doc.text(40, 600, 'Contributors:');

                doc.setFontSize(12);
                doc.setFont("arial");
                doc.setFontType("normal");
                var cDescription = "Here will be our production description. Here will be our production description.";
                var splitCont = doc.splitTextToSize(cDescription, 260);
                doc.text(40, 620, splitCont);

                doc.setFontSize(10);
                doc.setFont("arial");
                doc.setFontType("normal");
                doc.text(40, 680, 'Production Pin: EPIN001');

                doc.setFontSize(10);
                doc.setFont("arial");
                doc.setFontType("normal");
                doc.text(40, 700, 'Storyboard Printed On: 10/12/2018');

                doc.setFontSize(10);
                doc.setFont("arial");
                doc.setFontType("normal");
                doc.text(40, 720, 'By: GSV');

                //////////// Seconnd Page////////////

                doc.addPage('a4','p');
                doc.addImage(sPage, 'JPEG', 0, 0, 595, 842);

                doc.setFontSize(20);
                doc.setFont("arial");
                doc.setFontType("bold");
                doc.text(250, 80, 'Storyboard');
                doc.addImage(pImage, 'JPEG', 70, 310, 256, 150);
                doc.setTextColor(100);
                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("bold");
                doc.text(70, 265, '1. Intro');
                doc.setFontType("normal");
                doc.text(270, 265, '5 sec');

                doc.setTextColor(100);
                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("normal");
                doc.text(70, 285, 'Title of Scene');

                doc.setTextColor(100);
                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("normal");
                doc.text(340, 120, 'Description');

                doc.setFontSize(12);
                doc.setFont("arial");
                doc.setFontType("normal");
                var desc1 = "Here will be our production Name.Here will be our production Name.Here will be our production Name.";
                var splitDesc1 = doc.splitTextToSize(desc1, 220);
                doc.text(340, 140, splitDesc1);

                doc.setTextColor(100);
                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("bold");
                doc.text(70, 480, '2. Title Card');
                doc.setFontType("normal");
                doc.text(270, 480, 'Duration');

                doc.setTextColor(100);
                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("normal");
                doc.text(70, 500, 'Title of Scene');

                doc.setTextColor(100);
                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("normal");
                doc.text(340, 320, 'Description');

                doc.setFontSize(12);
                doc.setFont("arial");
                doc.setFontType("normal");
                var desc2 = "Here will be our production Name.Here will be our production Name.Here will be our production Name.";
                var splitDesc2 = doc.splitTextToSize(desc2, 220);
                doc.text(340, 340, splitDesc2);

                doc.addImage(pImage, 'JPEG', 70, 530, 256, 150);
                doc.setTextColor(100);
                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("bold");
                doc.text(70, 700, '3. Full Video');
                doc.setFontType("normal");
                doc.text(270, 700, 'Duration');

                doc.setTextColor(100);
                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("normal");
                doc.text(70, 720, 'Title of Scene');

                doc.setTextColor(100);
                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("normal");
                doc.text(340, 540, 'Description');

                doc.setFontSize(12);
                doc.setFont("arial");
                doc.setFontType("normal");
                var desc3 = "Here will be our production Name.Here will be our production Name.Here will be our production Name.";
                var splitDesc3 = doc.splitTextToSize(desc3, 220);
                doc.text(340, 560, splitDesc3);

                doc.setTextColor(100);
                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("normal");
                doc.text(340, 640, 'Teleprometer');

                doc.setFontSize(12);
                doc.setFont("arial");
                doc.setFontType("normal");
                var desc4 = "Here will be our production Name.Here will be our production Name.Here will be our production Name.";
                var splitDesc4 = doc.splitTextToSize(desc4, 220);
                doc.text(340, 660, splitDesc4);


                ////////////   Third Page /////////////////


                doc.addPage('a4','p');
                doc.addImage(oPage, 'JPEG', 0, 0, 595, 842);

                doc.addImage(pImage, 'JPEG', 70, 60, 256, 150);
                doc.setTextColor(100);
                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("bold");
                doc.text(70, 230, '4. Split Screen');
                doc.setFontType("normal");
                doc.text(270, 230, 'Duration');

                doc.setTextColor(100);
                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("normal");
                doc.text(70, 250, 'Title of Scene');

                doc.setTextColor(100);
                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("normal");
                doc.text(340, 70, 'Description');

                doc.setFontSize(12);
                doc.setFont("arial");
                doc.setFontType("normal");
                var desc4 = "Here will be our production Name.Here will be our production Name.Here will be our production Name.";
                var splitDesc4 = doc.splitTextToSize(desc4, 220);
                doc.text(340, 90, splitDesc4);

                doc.addImage(pImage, 'JPEG', 70, 270, 256, 150);
                doc.setTextColor(100);
                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("bold");
                doc.text(70, 440, '5. Outro');
                doc.setFontType("normal");
                doc.text(270, 440, 'Duration');

                doc.setTextColor(100);
                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("normal");
                doc.text(70, 460, 'Title of Scene');

                doc.setTextColor(100);
                doc.setFontSize(14);
                doc.setFont("arial");
                doc.setFontType("normal");
                doc.text(340, 280, 'Description');

                doc.setFontSize(12);
                doc.setFont("arial");
                doc.setFontType("normal");
                var desc5 = "Here will be our production Name.Here will be our production Name.Here will be our production Name.";
                var splitDesc5 = doc.splitTextToSize(desc5, 220);
                doc.text(340, 300, splitDesc5);
                doc.save("GSV.pdf");
                //doc.output('dataurlnewwindow');

            }

  render() {
    return (
      <div className="App">
        <div className="mb5 btn1">
          <button onClick={this.printDocument}> Print </button>
        </div>
        <div id="divToPrint" className="mt4" >
        <h1>¯\_(ツ)_/¯</h1>
        <h1>( ^_^)o自自o(^_^ )</h1>
        </div>
      </div>
    );
  }
}

export default App;

评论:我无法在https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.radiobuttonlist?view=netframework-4.7.2中找到与此有关的文档;在“声明性语法”下,在ListItem下提到了Value属性,但没有迹象表明在PostBack上确定所选元素是必需的(根据Martin Ullrich的研究)。