比较gridview中的两个用户控制日期选择器 [英] compare two User Control date picker inside gridview
问题描述
我有一个使用ajax工具包的日历用户控件。
i我在两个日期字段(开始日期和结束日期)中两次使用gridview中的用户控件
我如何比较两个日期???
我尝试使用比较验证器,但它没有得到用户控件内的文本框ID 。
非常感谢一些想法..
谢谢
这是我的用户控件
I have a generic user control for calenders using ajax toolkit.
i am using the user control in a gridview twice for two date fields ("Start Date" and "End Date")
How do i compare the two dates???
I tried it using the compare validator but it doesnt get the textbox id which is inside the usercontrol.
Would appreciate some ideas..
Thanks
This is my user control
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AjaxDatePicker.ascx.cs" Inherits="TCS.AjaxDatePicker" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:TextBox ID="txtDatePicker" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="calExtndDatePicker" TargetControlID="txtDatePicker"
runat="server">
</asp:CalendarExtender>
推荐答案
这是gridview中的比较验证器
this is compare validator inside gridview
<asp:comparevalidator id="CompareValidator1" runat="server" errormessage="CompareValidator" xmlns:asp="#unknown"></asp:comparevalidator>
<asp:ajaxdatepicker id="UControl2" title="Date Picker" runat="server" xmlns:asp="#unknown"></asp:ajaxdatepicker>
这是设置控件以验证属性后面的代码
and this is my code behind for setting the control to validate property
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
AjaxDatePicker ajx = (AjaxDatePicker)e.Row.FindControl("UControl1");
TextBox txtDatepicker = (TextBox)ajx.FindControl("txtDatePicker");
// string id = txtDatepicker.UniqueID;
AjaxDatePicker ajx1 = (AjaxDatePicker)e.Row.FindControl("UControl2");
TextBox txtDatepicker1 = (TextBox)ajx.FindControl("txtDatePicker");
//string id = txtDatepicker1.UniqueID;
CompareValidator cmp = (CompareValidator)e.Row.FindControl("CompareValidator1");
cmp.ControlToValidate = txtDatepicker1.UniqueID;
// string id=
}
}
我在运行页面时收到以下错误
无法找到控件ID'ctl00
I am getting the following error on running the page
Unable to find control id 'ctl00
ContentPlaceHolder1
ContentPlaceHolder1
GridView1
GridView1
这篇关于比较gridview中的两个用户控制日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!