?? default.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;
namespace ASPNET.StarterKit.Communities.Admin.CustomRedirects
{
//*******************************************************
//
// Initialize the Page.
//
//*******************************************************
public class _Default : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgrdRedirects;
protected System.Web.UI.WebControls.Panel pnlNoRedirects;
protected System.Web.UI.WebControls.Panel pnlRedirects;
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
BindRedirects();
CommunityInfo objCommunityInfo = (CommunityInfo)Context.Items["CommunityInfo"];
}
}
//*******************************************************
//
// Bind list of redirects to the DataGrid.
//
//*******************************************************
void BindRedirects()
{
// Bind the list of Topics
dgrdRedirects.DataSource = CustomRedirectUtility.GetCustomRedirects();
dgrdRedirects.DataKeyField = "SourceURL";
dgrdRedirects.DataBind();
if (dgrdRedirects.Items.Count == 0)
{
pnlNoRedirects.Visible = true;
pnlRedirects.Visible = false;
}
}
private void DataGrid_ItemDataBound(Object s, DataGridItemEventArgs e)
{
// Don't do any binding in header or footer
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
// Get Redirectinfo Info from DataItem
CustomRedirectInfo redirectInfo = (CustomRedirectInfo)e.Item.DataItem;
// Get Controls from template
Label SourceURL = (Label)e.Item.FindControl("SourceURL");
Label DestURL = (Label)e.Item.FindControl("DestURL");
CheckBox IsSection = (CheckBox)e.Item.FindControl("IsSection");
// Assign values
SourceURL.Text = redirectInfo.SourceURL;
DestURL.Text = redirectInfo.DestinationURL;
IsSection.Checked = redirectInfo.IsSectionRedirect;
IsSection.Enabled = false;
// Add edit url to edit link
HyperLink lnkEdit = (HyperLink)e.Item.FindControl("lnkEdit");
lnkEdit.NavigateUrl= String.Format("EditRedirect.aspx?source={0}", Page.Server.UrlEncode((string)DataBinder.Eval(e.Item.DataItem, "SourceURL")));
// Add confirmation to delete btn
ImageButton btnDelete = (ImageButton)e.Item.FindControl("btnDelete");
btnDelete.Attributes.Add("onclick",String.Format("return confirm('Are you sure you want to delete the \"{0}\" Redirect?')", redirectInfo.SourceURL));
}
}
//*******************************************************
//
// User clicked the Delete link.
//
//*******************************************************
void Item_Click(Object s, DataGridCommandEventArgs e)
{
string sourceURL = (string)dgrdRedirects.DataKeys[e.Item.ItemIndex];
if (e.CommandName=="Delete")
{
CustomRedirectUtility.DeleteRedirect(sourceURL);
BindRedirects();
}
}
#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.dgrdRedirects.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.Item_Click);
this.dgrdRedirects.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -