我很抱歉这个问题,但不知何故我停电(我知道这不是借口)但我如何从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();
}
}
}
}
答案 0 :(得分: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();
您可能需要格式化特定格式的数字,所以see this有关如何定制数字输入的具体信息,具体来说:
<NumberFormat DecimalDigits="0" />
将方法的值提供为:
mng.CalcForNextYear(Convert.ToInt32(fromYear.Value.Value),
Convert.ToInt32(toYear.Value.Value));
那应该可以解决问题。您必须在RadNumericTextBox控件中有一个值才能使其生效。否则,请先检查是否为空。
答案 1 :(得分:0)
int fromyearvalue = convert.toint32(fromYear.text)
int toyearvalue = convert.toint32(toYear.text)
mng.CalcForNextYear(fromyearvalue ,toyearvalue );
OR
mng.CalcForNextYear(= convert.toint32(fromYear.totext)),convert.toint32(toYear.totext));