[请教]按照书上的组件写的,编译的时候说少了NameValueCollection的using

Yamir2004 2004-04-29 09:49:06
小弟初学,一直没有找出解决办法 - -!
请各位大哥指点一下

下边代码的NameObjectCollection出错了

public bool LoadPostData(String postDataKey,NameObjectCollection values)
{
String clientDate = values[UniqueID + "_CurrentDate"];
if(clientDate != null)
currentDate = DateTime.Parse(clientDate);
return false;
}


源代码如下

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace Rili
{
public class Calendar : Control, IPostBackEventHandler, IPostBackDataHandler
{
private String[] monthNames = new String[12];
private DateTime currentDate = DateTime.Now;
private String backColor = "#dcdcdc";
private String foreColor = "#eeeeee";


protected override void Init()
{
Page.RegisterRequiresPostBack(this);
Page.RegisterPostBackScript();

currentDate = DateTime.Now;

monthNames[0] = "一月";
monthNames[1] = "二月";
monthNames[2] = "三月";
monthNames[3] = "四月";
monthNames[4] = "五月";
monthNames[5] = "六月";
monthNames[6] = "七月";
monthNames[7] = "八月";
monthNames[8] = "九月";
monthNames[9] = "十月";
monthNames[10] = "十一月";
monthNames[11] = "十二月";
}


protected override void LoadState(Object viewState)
{
if(null!=viewState)
{
currentDate = DateTime.Parse((String) viewState);
}
}

public void RaisePostBackEvent(String eventArgument)
{
if(eventArgument == null)
{
return;
}
DateTime oldDate = currentDate;
if(String.Compare("NavNextMonth",eventArgument,true) == 0)
{
currentDate = currentDate.AddMonths(1);
}
else if(String.Compare("NavPreMonth",eventArgument,true) == 0)
{
currentDate = currentDate.AddMonths(-1);
}
else
{
int daySelected = Int32.Parse(eventArgument);
currentDate = new DateTime(currentDate.Year,currentDate.Month,daySelected);
}
}


protected override Object SaveState()
{
return currentDate.ToString();
}


protected override void Render(HtmlTextWriter output)
{
if(Page.Request.UserAgent.IndexOf("MSIE 5.5")!=-1)
RenderUpLevel(output);
else
RenderDownLevel(output);
}


protected void RenderUpLevel(HtmlTextWriter output)
{
output.WriteLine("<input name='" +UniqueID + "_CurrentDate' id='" + UniqueID + "_CurrentDate' type=hidden>");
output.WriteLine("<span id='" +UniqueID + "'></span>");
output.WriteLine("<script language=jscript>drawcalendar('" + UniqueID + "','" + Int32.Format(currentDate.Month,null) + "/" + Int32.Formar(currentDate.Day,null) + "');</script>");
}
...全文
47 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Yamir2004 2004-04-29
  • 打赏
  • 举报
回复
刚刚也试过这个。。可能我写错了。。。

多谢楼上的大哥了
cuike519 2004-04-29
  • 打赏
  • 举报
回复
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Collections.Specialized;//添加这一行试一试
Yamir2004 2004-04-29
  • 打赏
  • 举报
回复
protected void RenderDownLevel(HtmlTextWriter output)
{
output.WriteLine("<table bgcolor=" + backColor + " border=0 height=190 valign=top><tr><td>");
output.WriteLine("<table bgcolor=" + backColor + " border=0 height=190 valign=top>");
output.WriteLine("<tr><td>");
output.WriteLine("<center>");
output.WriteLine("<a href=\"javascript:" + Page.GetPostBackEventReference(this,"NavPrevMonth") + "\">");
output.WriteLine("<img src=/quickstart/aspplus/images/left4.gif width=11 height=11 border=0></a>");
output.WriteLine("<b>" + Int32.Format(currentDate.Year,null) + " " + monthNames[currentDate.Month-1] + "</b>");
output.WriteLine("<a href=\"javascript:" + Page.GetPostBackEventReference(this,"NavNextvMonth") + "\">");
output.WriteLine("<img src=/quickstart/aspplus/images/right4.gif width=11 height=11 border=0></a>");
output.WriteLine("</center>");
output.WriteLine("</td></tr>");
output.WriteLine("<tr valign=top><td valign=top>");
output.WriteLine("<table border=1 bgcolor=" + foreColor + " height=160>");
output.WriteLine("<tr height=20>");
output.WriteLine("<td align=center width=60>星期天</td>");
output.WriteLine("<td align=center width=60>星期一</td>");
output.WriteLine("<td align=center width=60>星期二</td>");
output.WriteLine("<td align=center width=60>星期三</td>");
output.WriteLine("<td align=center width=60>星期四</td>");
output.WriteLine("<td align=center width=60>星期五</td>");
output.WriteLine("<td align=center width=60>星期六</td>");
output.WriteLine("</tr>");
output.WriteLine("<tr>");

int numDays = DateTime.DaysInMonth(currentDate.Year,currentDate.Month);
int firstDay = new DateTime(currentDate.Year,currentDate.Month,1).DayOfWeek;

for(int x=0;x<firstDay;x++)
{
output.WriteLine("<td align=right width=23></td>");
}

for(int x=1;x<=numDays;x++)
{
if(currentDate.Day == x)
{
output.Write("<td align=center width=60>");
output.Write("<font color=red><b><u>" + Int32.Format(x,null) + "</u></b></font>");
output.WriteLine("</td>");
}
else
{
output.Write("<td align=center width=60>");
output.Write("<a href=\"javascript:" + Page.GetPostBackEventReference(this,Int32.Format(x,null)) +"\">");
output.Write(Ine32.Format(x,null) + "</a>");
output.WriteLine("</td>");
}

if(((firstDay+x)%7)==0)
{
output.WriteLine("</tr><tr>");
}
}

output.WriteLine("</tr>");
output.WriteLine("</table></td></tr></table></table>");
}


public DateTime Date
{
get
{
return currentDate;
}
set
{
currentDate = value;
}
}


public String BackColor
{
get
{
return backColor;
}
set
{
backColor = value;
}
}


public String ForeColor
{
get
{
return foreColor;
}
set
{
foreColor = value;
}
}


public bool LoadPostData(String postDataKey,NameObjectCollection values)
{
String clientDate = values[UniqueID + "_CurrentDate"];
if(clientDate != null)
currentDate = DateTime.Parse(clientDate);
return false;
}


public void RaisePostDataChangedEvent()
{
}


}
}
Yamir2004 2004-04-29
  • 打赏
  • 举报
回复
protected override void PreRender()
{
String DHTMLFunction = "";

DHTMLFunction += "<script language='JavaScript'>\n";
DHTMLFunction += "function drawcalendar(calname,newDate)\n";
DHTMLFunction += "{\n";
DHTMLFunction += "var CurrentDate = new Date(newDate);\n";
DHTMLFunction += "var MonthArray = new Array('一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月');\n";
DHTMLFunction += "var MonthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);\n";
DHTMLFunction += "var calText;\n";
DHTMLFunction += "calText ='<table bgcolor=#dcdcdc border=0 height=190 valign=top>';\n";
DHTMLFunction += "calText = calText + '<tr><td>';\n";
DHTMLFunction += "calText = calText + '<center>';\n";
DHTMLFunction += "calText = calText + \"<a herf='javascript: drawclendar(\\\"\" + calname + \"\\\",\\\"\" + CurrentDate.getFullYear() + \"/\" + CurrentDate.getMonth() + \"/\" + CurrentDate.getDate() + \"\\\")'>\";\n";
DHTMLFunction += "calText = calText + '<img src=/quickstart/aspplus/images/left4.gif width=11 height=11 border=0></a>';\n";
DHTMLFunction += "calText = calText + '<b>' + CurrentDate.getFullYear() + ' ' + MonthArray[CurrentDate.getMonth()] + '</b>';\n";
DHTMLFunction += "calText = calText + \" <a href='javascript: drawcalendar(\\\"\" + calname + \"\\\",\\\"\" + CurrentDate.getFullYear() +\"/\" + (CurrentDate.getMonth() + 2) + \"/\" + CurrentDate.getDate() + \"\\\")'>\";\n";
DHTMLFunction += "calText = calText + '<img src=/quickstart/aspplus/images/right4.gif width=11 height=11 border=0></a>';\n";
DHTMLFunction += "calText = calText + '</center>';\n";
DHTMLFunction += "calText = calText + '</tr></td>';\n";
DHTMLFunction += "calText = calText + '<tr valign=top><td valign=top>';\n";
DHTMLFunction += "calText = calText + '<table border=1 bgcolor=#eeeeee height=160>';\n";
DHTMLFunction += "calText = calText + '<tr height=20>';\n";
DHTMLFunction += "calText = calText + '<td align=center width=60>星期天</td>';\n";
DHTMLFunction += "calText = calText + '<td align=center width=60>星期一</td>';\n";
DHTMLFunction += "calText = calText + '<td align=center width=60>星期二</td>';\n";
DHTMLFunction += "calText = calText + '<td align=center width=60>星期三</td>';\n";
DHTMLFunction += "calText = calText + '<td align=center width=60>星期四</td>';\n";
DHTMLFunction += "calText = calText + '<td align=center width=60>星期五</td>';\n";
DHTMLFunction += "calText = calText + '<td align=center width=60>星期六</td>';\n";
DHTMLFunction += "calText = calText + '</tr>';\n";
DHTMLFunction += "calText = calText + '<tr>';\n";
DHTMLFunction += "var numDays = MonthDays[CurrentDate.getMonth()];\n";
DHTMLFunction += "var firstDay = new Date(1999,8,1).getDay();\n";
DHTMLFunction += "for(var x=0;x<firstDay;x++)\n";
DHTMLFunction += "{\n";
DHTMLFunction += "calText = calText + '<td align=center width=60></td>'\n";
DHTMLFunction += "}\n";
DHTMLFunction += "for(var x=1;x<=numDays;x++)\n";
DHTMLFunction += "{\n";
DHTMLFunction += "if(CurrentDate.getDate()==x)\n";
DHTMLFunction += "{\n";
DHTMLFunction += "calText = calText + '<td align=center width=60>';\n";
DHTMLFunction += "calText = calText + '<font color=red><b><u>' + x + '</u></b></font>';\n";
DHTMLFunction += "calText = calText + '</td>';\n";
DHTMLFunction += "}\n";
DHTMLFunction += "else\n";
DHTMLFunction += "{\n";
DHTMLFunction += "calText = calText + '<td align=center width=60>';\n";
DHTMLFunction += "calText = calText + \"<a href='javascript: drawcalendar(\\\"\" + calname + \"\\\",\\\"\" + CurrentDate.getFullYear() +\"/\" + (CurrentDate.getMonth()+1) + \"/\" + x + \"\\\")'>\" + x + \"</a>\";";
DHTMLFunction += "calText = calText + '</td>';\n";
DHTMLFunction += "}\n";
DHTMLFunction += "if(((firstDay+x)%7)==0)\n";
DHTMLFunction += "{\n";
DHTMLFunction += "calText = calText + '</tr><tr>';\n";
DHTMLFunction += "}\n";
DHTMLFunction += "}\n";
DHTMLFunction += "calText = calText + '</tr>';";
DHTMLFunction += "calText = calText + '</table></td></tr></table>';";
DHTMLFunction += "var CalendarSpan = document.all(calname);";
DHTMLFunction += "if(CalendarSpan!=null)";
DHTMLFunction += "CalendarSpan.innerHTML = calText;";
DHTMLFunction += "var CalendarValue = document.all(calname + '_CurrentDate');";
DHTMLFunction += "if(CalendarValue!=null)";
DHTMLFunction += "CalendarValue.value = '' + (CurrentDate.getMonth() + 1) + '/' + CurrentDate.getDate() + '/' + CurrentDate.getFullYear();";
DHTMLFunction += "}\n";
DHTMLFunction += "</script>\n";

if(Page.Request.UserAgent.IndexOf("MSIE 5.5") != -1)
Page.RegisterClientScriptBlock("RILI_CALENDAR_DHTML",DHTMLFunction);

}


62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧