Click here to Skip to main content
15,881,172 members
Articles / Web Development / ASP.NET

NoSpamEmailHyperlink: 1. Design

Rate me:
Please Sign up or sign in to vote.
4.90/5 (29 votes)
22 Oct 200312 min read 213.1K   3.8K   99  
Fighting back against the e-mail harvesters.
<%@ Page language="c#" %>
<%@ Register TagPrefix="cpspam" Namespace="CP.WebControls" Assembly="CP.WebControls.NoSpamEmailHyperlink" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
	<head>
		<title>NoSpamEmailHyperlink Example 2 - Databinding</title>
		<script runat="server">
		
			private void Page_Load(object sender, System.EventArgs e)
			{
				ArrayList list = new ArrayList();
				list.Add(new Person(1, "Paul Riley", "pdriley@santt.com"));
				list.Add(new Person(2, "David Duncan-Smythe", "david@duncan-smythe.com"));
				list.Add(new Person(3, "Jim Jones", "jim_jones@britdomain.co.uk"));

				DataGrid1.DataSource = list;
				if (!IsPostBack) this.DataBind();
			}
			
			public class Person
			{
				private int _id = 0;
				private string _name = "";
				private string _email = "";

				public Person (int NewID, string NewName, string NewEmail) : base()
				{
					_id = NewID;
					_name = NewName;
					_email = NewEmail;
				}

				public int ID {
					get { return _id; }
					set { _id = value; }
				}
				public string Name {
					get { return _name; }
					set { _name = value; }
				}
				public string Email {
					get { return _email; }
					set { _email = value; }
				}
			}
			
		</script>
	</head>
	<body>
		<form id="myForm" method="post" runat="server">
			<asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False" CellPadding="2" CellSpacing="3">
				<AlternatingItemStyle BackColor="#E0E0E0" />
				<HeaderStyle BackColor="#FFC080" />
				<Columns>
					<asp:BoundColumn DataField="ID" HeaderText="ID">
						<HeaderStyle Width="30px" HorizontalAlign="Right" />
						<ItemStyle HorizontalAlign="Right" />
					</asp:BoundColumn>
					<asp:TemplateColumn>
						<HeaderStyle Width="100px" />
						<HeaderTemplate>
							Person
						</HeaderTemplate>
						<ItemTemplate>
							<cpspam:NoSpamEmailHyperlink id="nseh" runat="server"
								Email='<%# DataBinder.Eval(Container.DataItem, "Email") %>'
								ScrambleSeed='<%# DataBinder.Eval(Container.DataItem, "ID") %>'>
								<%# DataBinder.Eval(Container.DataItem, "Name") %>
								(<%# DataBinder.Eval(Container.DataItem, "Email") %>)
							</cpspam:NoSpamEmailHyperlink>
						</ItemTemplate>
					</asp:TemplateColumn>
				</Columns>
			</asp:datagrid>
		</form>
	</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United Kingdom United Kingdom
Paul lives in the heart of En a backwater village in the middle of England. Since writing his first Hello World on an Oric 1 in 1980, Paul has become a programming addict, got married and lost most of his hair (these events may or may not be related in any number of ways).

Since writing the above, Paul got divorced and moved to London. His hair never grew back.

Paul's ambition in life is to be the scary old guy whose house kids dare not approach except at halloween.

Comments and Discussions