📄 defaultcs.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
namespace Telerik.MenuExamplesCSharp.Menu.Examples.Design.AdvancedTemplates
{
/// <summary>
/// Summary description for DefaultCS.
/// </summary>
public class DefaultCS : Telerik.QuickStart.XhtmlPage
{
protected Telerik.WebControls.RadMenu RadMenu1;
protected System.Web.UI.WebControls.Label Label1;
DataTable SampleTable = null;
private void CreateSampleTable()
{
SampleTable = new DataTable();
DataColumn col1 = new DataColumn("UserName", typeof(System.String));
//col1
DataColumn col2 = new DataColumn("UserBirthDay", typeof(System.String));
DataColumn col3 = new DataColumn("UserDetails", typeof(System.String));
SampleTable.Columns.Add(col1);
SampleTable.Columns.Add(col2);
SampleTable.Columns.Add(col3);
}
private void PopulateSampleTable()
{
DataRow TmpRow = SampleTable.NewRow();
TmpRow["UserName"] = "John Doe";
TmpRow["UserBirthDay"] = "01/01" + "/" + "1963";
TmpRow["UserDetails"] = "No details for that person";
SampleTable.Rows.Add(TmpRow);
TmpRow = SampleTable.NewRow();
TmpRow["UserName"] = "Hristo Stoichkov";
TmpRow["UserBirthDay"] = "02/08" + "/" + "1966";
TmpRow["UserDetails"] = "The best football player of the 90's";
SampleTable.Rows.Add(TmpRow);
TmpRow = SampleTable.NewRow();
TmpRow["UserName"] = "Tazz";
TmpRow["UserBirthDay"] = "01/01" + "/" + "1951";
TmpRow["UserDetails"] = "Taz, the tazmanian devil";
SampleTable.Rows.Add(TmpRow);
}
protected void Button1_Click(object sender, System.EventArgs e)
{
DataRow TmpRow = SampleTable.NewRow();
TmpRow["UserName"] = ((TextBox)RadMenu1.FindControl("FirsdtName")).Text;
DateTime TmpDate = DateTime.Parse(((TextBox)RadMenu1.FindControl("FirsddtName")).Text );
TmpRow["UserBirthDay"] = TmpDate;//.Month.ToString() + "/" + TmpDate.Day.ToString() + "/" + DateTime.Now.Year.ToString();
TmpRow["UserDetails"] = ((TextBox)RadMenu1.FindControl("FirstNdame")).Text;
SampleTable.Rows.Add(TmpRow);
DataGrid TmpGrid = ((DataGrid)RadMenu1.FindControl("DataGrid1"));
SampleTable.AcceptChanges();
TmpGrid.DataSource = SampleTable;
TmpGrid.DataBind();
Session["ExampleTable"] = SampleTable;
}
public void DayRender(Object source, DayRenderEventArgs e)
{
for (int i=0;i<SampleTable.Rows.Count;i++)
{
DateTime TmpDate = DateTime.Parse((String)SampleTable.Rows[i][1]);
String TmpStrDate = TmpDate.Month.ToString() + "/" + TmpDate.Day.ToString() + "/" + DateTime.Now.Year.ToString();
if (e.Day.Date == DateTime.Parse(TmpStrDate))
{
e.Cell.BackColor=System.Drawing.Color.Yellow;
e.Cell.ToolTip = (String)SampleTable.Rows[i][2];
}
}
}
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
CreateSampleTable();
PopulateSampleTable();
Session["ExampleTable"] = SampleTable;
DataGrid TmpGrid = ((DataGrid)RadMenu1.FindControl("DataGrid1"));
TmpGrid.DataSource = SampleTable;
TmpGrid.DataBind();
Button TmpBtn = ((Button)RadMenu1.FindControl("Button1"));
TextBox TmpBox = ((TextBox)RadMenu1.FindControl("FirsddtName"));
TmpBtn.Attributes["onclick"] = "return ClientDateValidate('" + TmpBox.ClientID + "');" ;
TmpBtn.Attributes["class"]="button";
}
else
{
if (Session["ExampleTable"] != null)
{
SampleTable = ((DataTable)(Session["ExampleTable"]));
DataGrid TmpGrid = ((DataGrid)RadMenu1.FindControl("DataGrid1"));
TmpGrid.DataSource = SampleTable;
TmpGrid.DataBind();
}
}
}
// Fixing the calendar control XHTML output.
protected override void Render(HtmlTextWriter writer)
{
StringWriter stringWriter = new StringWriter();
HtmlTextWriter newWriter = new HtmlTextWriter(stringWriter);
base.Render(newWriter);
string pageHtml = stringWriter.ToString();
pageHtml = pageHtml.Replace("<td align=\"Center\"", "<td align=\"center\"");
pageHtml = pageHtml.Replace("<td align=\"Right\"", "<td align=\"right\"");
pageHtml = pageHtml.Replace("<td align=\"Left\"", "<td align=\"left\"");
writer.Write(pageHtml);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -