<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC"
BorderStyle="None" BorderWidth="1px" CellPadding="4"
DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Horizontal"
Width="900px">
<Columns>
<asp:TemplateField HeaderText="Date" SortExpression="Date">
<EditItemTemplate>
<asp:TextBox ID="txtStartDate" runat="server" Text='<%# Bind("Date") %>'></asp:TextBox>
<asp:CalendarExtender
ID="CalendarExtender1"
onprerender="AjaxCalendar_PreRender"
runat="server"
TargetControlID="txtStartDate"
Format="dd/MM/yyyy" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Date is required" Font-Italic="True" Font-Size="Small"
ForeColor="Red" ControlToValidate="txtStartDate"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Date") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Time" SortExpression="Start_Time">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Start_Time") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Start_Time") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:CommandField ShowEditButton="True">
<ItemStyle ForeColor="#003366" />
</asp:CommandField>
</Columns>
</asp:GridView>
我想设置具有特定日期范围的日历。
protected void AjaxCalendar_PreRender(object sender, EventArgs e)
{
DateTime startDate = DateTime.Now.AddDays(1);
DateTime endDate = DateTime.Now.AddDays(60);
CalendarExtender ce = (CalendarExtender)GridView1.FindControl("CalendarExtender1");
ce.StartDate = startDate;
ce.EndDate = endDate;
}
这就是我所做的,但是我没有将对象引用设置为对象的实例。是不是 GridView FindControl 导致了错误?