Here I have created sample as per your requirement.
HTML
<div>
<asp:DataList ID="datalistproduct" runat="server" RepeatColumns="4" RepeatLayout="Flow"
OnItemDataBound="datalistproduct_ItemDataBound">
<ItemTemplate>
<asp:HyperLink ID="hlProductId" NavigateUrl='<%# Eval("Product_Id","/ProductDetails.aspx?pitem={0}") %>'
runat="server" Text="View Product" />
</ItemTemplate>
</asp:DataList>
</div>
Code
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Product_Id");
dt.Rows.Add("a456d");
dt.Rows.Add("fr85d");
datalistproduct.DataSource = dt;
datalistproduct.DataBind();
}
protected void datalistproduct_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item)
{
string productId = ((HyperLink)e.Item.FindControl("hlProductId")).NavigateUrl;
productId = productId.Split('?')[1];
productId = productId.Substring(6, productId.Length - 6);
string encryptedProductId = Encrypt(productId);
((HyperLink)e.Item.FindControl("hlProductId")).NavigateUrl = string.Format("/ProductDetails.aspx?pitem={0}", encryptedProductId);
}
}
private string Encrypt(string clearText)
{
string EncryptionKey = "MAKV2SPBNI99212";
byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(clearBytes, 0, clearBytes.Length);
cs.Close();
}
clearText = Convert.ToBase64String(ms.ToArray());
}
}
return clearText;
}
I hope this will help you out.