2
有一個關於我在哪裏上 開工的項目問題這是一個日曆,你可以把註釋以一個特殊的日子/年Asp.net日曆我如何
我使用ATM的ASP。網日曆控制。
下面是這一理念的形象:
下面是標記代碼:
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Calender.master" CodeFile="Calender.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<form id="Form1" runat="server">
<asp:ScriptManager ID="SM1" runat="server" />
<asp:UpdatePanel ID="UP1" runat="server">
<ContentTemplate>
<asp:Calendar ID="Calendar1" ShowGridLines="true" CellPadding="15" runat="server"
OnDayRender="Calendar1_DayRender" OnSelectionChanged="Calendar1_SelectionChanged ">
</asp:Calendar>
<br />
<asp:FormView ID="FormView1" runat="server" AllowPaging="true"
DataKeyNames="date" DataSourceID="todoSrc" DefaultMode="Edit">
<EditItemTemplate>
<asp:Label ID="lblTodo" runat="server" AssociatedControlID="txtTodo" Text="Afspraak:" />
<br />
<asp:TextBox ID="txtTodo" runat="server" TextMode="MultiLine" Columns="30" Rows="5"
Text="<%# Bind('todo') %>"></asp:TextBox>
<br /><br />
<asp:LinkButton ID="butUpdate" runat="server" Text="Update" CommandName="Update" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:Label ID="lblTodo" runat="server" Text="Toevoegen:" AssociatedControlID="txtTodo" />
<br />
<asp:TextBox ID="txtTodo" runat="server" Text="<%# Bind('todo') %>" TextMode="MultiLine"
Columns="30" Rows="5" />
<br />
<asp:Button ID="butInsert" runat="server" Text="Add" CommandName="Insert" />
</InsertItemTemplate>
</asp:FormView>
<br />
<asp:Button ID="butAddNew" runat="server" Text="Toevoegen" OnClick="butAddNew_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<SelectParameters>
<asp:SqlDataSource ID="todoSrc" runat="server" ConnectionString="<%$ ConnectionStrings:Stefan %>"
DeleteCommand="DELETE Calender WHERE [email protected]" InsertCommand="INSERT Calender (date,todo) VALUES (@date,@todo)"
SelectCommand="SELECT * FROM Calender WHERE [email protected]" UpdateCommand="UPDATE Calender SET [email protected] WHERE [email protected]">
<SelectParameters>
<asp:ControlParameter Name="date" ControlID="Calendar1" PropertyName="SelectedDate" />
</SelectParameters>
<InsertParameters>
<asp:ControlParameter Name="date" ControlID="Calendar1" PropertyName="SelectedDate" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="calendarSrc" runat="server" ConnectionString="<%$ ConnectionStrings:Stefan %>"
SelectCommand="SELECT date FROM Calender"></asp:SqlDataSource>
</form>
</asp:Content>
這裏是代碼隱藏CS文件
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
DataView todo = new DataView();
protected void Page_Load(object sender, EventArgs e)
{
if (Calendar1.SelectedDate == DateTime.MinValue)
Calendar1.SelectedDate = Calendar1.TodaysDate;
}
void Page_PreRender()
{
todo = (DataView)calendarSrc.Select(DataSourceSelectArguments.Empty);
todo.Sort = "date";
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (todo.FindRows(e.Day.Date).Length > 0)
e.Cell.BackColor = System.Drawing.Color.Aqua;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
FormView1.ChangeMode(FormViewMode.Edit);
}
protected void butAddNew_Click(object sender, EventArgs e)
{
FormView1.ChangeMode(FormViewMode.Insert);
}
}
在哪裏的問題? – Cynede
我的問題是我該如何做,就像我在圖像中描繪的那樣 –