SharePoint 2010 日期控件(DateTimeControl)的用法
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server"> <SharePoint:DateTimeControl ID="DateTimeControl1" runat="server" /> <br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> <br /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </asp:Content> protected void Button1_Click(object sender, EventArgs e) { DateTime dt= DateTimeControl1.SelectedDate; int hour=dt.Hour; String format = String.Format("yyyy-MM-dd {0}:mm:ss",hour.ToString().PadLeft(2, '0')); String strDateTime = dt.ToString(format); TextBox1.Text = strDateTime; }
http://www.cnblogs.com/sygwin/archive/2011/11/04/2236752.html
SharePoint 2010 日期控件(DateTimeControl)的用法
2011-11-04 23:52 by 四毛的家, 811 阅读, 0 评论, 收藏, 编辑
Sharepoint 2010添加栏时,有个日期和时间类型,它呈现的其实是一个日期控件,非常酷。那么我们如何在我们的页面,比如Application Page中,使用该控件呢?
DateTimeControl控件所在的命名空间是:Microsoft.SharePoint.WebControls,所在的dll是Microsoft.SharePoint.dll。 默认情况下,该控件并没有添加到vs2010的工具箱中,你需要右击工具箱,选择项,将其添加到工具箱中。然后拖放到需要的地方。

如果你使用的是sharepoint 2007.那么你需要在需要放置日期控件的页面顶部放置:
<%@ Register TagPrefix="spuc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
然后再需要的地方写:
<spuc:DateTimeControl runat="server" ID="DateTimePickerControl1" />。
重要属性:
SelectedDate:获取用户选择的日期。你也可以用代码指定。如果用户不选择,而你又未用代码指定,那么默认返回当前日期。
ErrorMessage:用户自定义错误时的提示信息。
MaxDate:你可以指定可以选择的最大日期。
MinDate:可以选择的最小日期。
AutoPostPack:是否自动回发。注意,如果设为true,你需要设置DateChanged事件。
IsRequiredField:指定是否为必填项。
更多属性,请查阅MSDN。
注意: 上面我们说如果用户不选择,那么SelectedDate默认返回的是当前日期。那么如何判断用户是否选择了日期呢?可以使用IsDateEmpty
if (!datetimepicker.IsDateEmpty)
{
newCustomer.StartDate = datetimepicker.SelectedDate;
}
本文参考文章:http://blog.qumsieh.ca/2011/04/01/datetimecontrol-saving-blank-values/
http://karinebosch.wordpress.com/sharepoint-controls/datetimecontrol-control/
注意,因为此刻我没有sharepoint环境,所以本文并未验证。仅供参考,有疑问请仔细阅读参考文章,如果打开不开,请想办法FQ。
« 上一篇:SharePoint 2010 使用自定义aspx页面替换列表默认的新建(NewForm.aspx),查看(DispForm.aspx)和编辑(EditForm.aspx)页面
» 下一篇:SharePoint 2010 使用SP.UI.ModalDialog.showModalDialog(options)对话框框架传值



浙公网安备 33010602011771号