|
<%@ 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.
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