gpt4 book ai didi

c# - Sharepoint 中的 DateTimeControl (c#)

转载 作者:行者123 更新时间:2023-12-02 13:25:13 26 4
gpt4 key购买 nike

我正在尝试更改 DateTimeControl 在 Sharepoint 中显示的“时间”下拉列表中的默认值。我想要增量 15 分钟,而不是 5 分钟。有人知道如何做到这一点吗?我可以重载方法或其他东西吗?

最佳答案

事实上,时间下拉菜单及其初始值设定项都是作为 DateTimeControl 类的私有(private)数据成员实现的,因此您无法直接更改这些值。然而,分钟下拉列表是在 OnPreRender 内部准备的,我们可以获取控件并间接重置其值以获得所需的行为。这是一种方法

public class MyDateTimeControl : DateTimeControl
{
protected override void Render(HtmlTextWriter output)
{
DropDownList minuteControl = null;
string[] newMinutesRange = new string[] { "00", "15", "30", "45" };
string[] newMinutesRangeExt = new string[] { "00", "15", "30", "45", "" };
int index = 0;
int selectedMinutes;

try
{
if (!this.DateOnly && this.Controls.Count == 4)
{
minuteControl = (DropDownList)this.Controls[2];
}
}
catch { }

if (minuteControl != null && !this.DateOnly)
{
selectedMinutes = Convert.ToInt32(minuteControl.SelectedValue);
if (selectedMinutes % 15 > 0)
{
index = 4;
newMinutesRangeExt.SetValue(selectedMinutes.ToString(), index);
newMinutesRange = newMinutesRangeExt;
}
else
{
index = selectedMinutes / 15;
}

minuteControl.Items.Clear();
minuteControl.SelectedIndex = 0;
minuteControl.DataSource = newMinutesRange;
minuteControl.DataBind();
minuteControl.SelectedIndex = index;
}

base.Render(output);
}
}

希望这有帮助

关于c# - Sharepoint 中的 DateTimeControl (c#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/972588/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com