1

我很抱歉这个问题,但不知何故我停电了(我知道这不是借口),但我怎样才能从RadNumbericTextBox使用按钮中检索值来发送值(我需要一个 int)

<div class="fromRowDiv">
   <asp:Label ID="label1" CssClass="fromLabel" runat="server" Text="From Date" ></asp:Label>
   <telerik:RadNumericTextBox ID="fromYear" runat="server" MinValue="2000" NumberFormat-DecimalDigits="0" NumberFormat-GroupSeparator="" ></telerik:RadNumericTextBox>   
   <asp:Label ID="Tolabel2" CssClass="fromLabel" runat="server" Text="To Date"></asp:Label>
   <telerik:RadNumericTextBox ID="toYear" runat="server" MinValue="2000" NumberFormat-DecimalDigits="0" NumberFormat-GroupSeparator=""></telerik:RadNumericTextBox>    
</div>

protected void CalcButton_Click(object sender, EventArgs e)
{
            AnnualVacationManager mng = new AnnualVacationManager();

            mng.CalcForNextYear(fromYear,toYear);
}

我需要来自 RadNumbericTextBox 的值(动态)

  public AnnualVacationManager() {
    }

    public void CalcForNextYear(int fromYear, int toYear)
    {
        IEnumerable<HtUser> allUsers = HtUser.GetAll();
        List<AnnualVacation> newAnnualVacations = new List<AnnualVacation>();
        if (allUsers.Any()) {
            foreach (HtUser user in allUsers) {
                //int fromYear = 2013;
                //int toYear = 2014;
                IEnumerable<AnnualVacation> usersCurrentAnnualVacation = new List<AnnualVacation>(user.AnnualVacations.Where(a =>a.FromDate.Value.Year >= fromYear && a.FromDate.Value.Year < toYear));
                if (usersCurrentAnnualVacation.Any()) {
                    foreach (AnnualVacation existing in usersCurrentAnnualVacation) {
                        AnnualVacation newAnnualVacation = new AnnualVacation();
                        //Year stuff
                        DateTime newFromDate = existing.FromDate.Value;
                        newFromDate.AddYears(toYear - fromYear);
                        DateTime newToDate = existing.ToDate.Value;
                        newToDate.AddYears(toYear - fromYear);
                        //
                        newAnnualVacation.FromDate = newFromDate;
                        newAnnualVacation.ToDate = newToDate;
                        newAnnualVacation.WorkingTime = existing.WorkingTime;
                        newAnnualVacation.VacationDays = existing.VacationDays + (existing.VacationDays - user.GetBookedVacation(fromYear));

                        newAnnualVacations.Add(newAnnualVacation);

                        newAnnualVacation.HtUser = user;
                    }
                }
            }

            HtEntityFactory.Context.SaveChanges();
        }
    }
}

}

4

2 回答 2

2

RadNumericTextBox 在服务器端有一个 Value 属性,它返回一个可以为空的十进制(或者可能是双精度)以及用户输入的数值。要获取该值,只要它提供了一个有效值,您可以:

//First .Value returns the nullable decimal or double
//second .Value gets the decimal or double in non-nullable form
fromYear.Value.Value

在客户端,它应该有一个get_value()方法来获取它,如下所示:

var box = $find("<%= fromYear.ClientID %>");
var val = box.get_value();

您可能需要将数字格式化为特定格式,因此请参阅此处了解如何定制数字输入的具体信息,特别是:

<NumberFormat DecimalDigits="0" />

将值提供给方法:

mng.CalcForNextYear(Convert.ToInt32(fromYear.Value.Value), 
   Convert.ToInt32(toYear.Value.Value));

这应该可以解决问题。您必须在 RadNumericTextBox 控件中有一个值才能使其工作。否则,首先检查 null。

于 2013-02-21T13:26:38.540 回答
0
int fromyearvalue = convert.toint32(fromYear.text)
int toyearvalue = convert.toint32(toYear.text)

 mng.CalcForNextYear(fromyearvalue ,toyearvalue );

或者

mng.CalcForNextYear(= convert.toint32(fromYear.totext)),convert.toint32(toYear.totext));
于 2013-02-21T13:26:35.130 回答