Hi OpeyemiOg,
I have created sample which fullfill requirement.
FirstPage: HTML
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvCustomers" DataSourceID="gridDatasource" AutoGenerateColumns="false"
runat="server">
<Columns>
<asp:TemplateField HeaderText="CustomerId">
<ItemTemplate>
<asp:Label ID="lblCustomer" Text='<%#Eval("CustomerId")%>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" Text="View" OnClick="Sent" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="gridDatasource" runat="server" ConnectionString="<%$ConnectionStrings:constring %>"
SelectCommand="SELECT * FROM Customers"></asp:SqlDataSource>
</div>
</form>
FirstPage: C#
private string Constr = ConfigurationManager.ConnectionStrings["Constring"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
}
}
protected void Sent(object sender, EventArgs e)
{
GridViewRow row = (sender as LinkButton).NamingContainer as GridViewRow;
string customerId = Convert.ToString((row.FindControl("lblCustomer") as Label).Text);
string cId = HttpUtility.UrlEncode(Encrypt(customerId));
Response.Redirect(string.Format("~/Default2.aspx?cId={0}", cId));
}
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;
}
SecondPage HTML
<form id="form1" runat="server">
<div>
<asp:Label ID="lblCustomerId" Visible="false" runat="server" />
<asp:DataList ID="dlcustomers" runat="server" DataSourceID="gridDatasource">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%#Eval("CustomerId") %>
</td>
<br />
<td>
<%#Eval("Name") %>
</td>
<br />
<td>
<%#Eval("Country")%>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
<asp:SqlDataSource ID="gridDatasource" runat="server" ConnectionString="<%$ConnectionStrings:constring %>"
SelectCommand="SELECT * FROM Customers" FilterExpression="CustomerId={0}">
<FilterParameters>
<asp:ControlParameter Name="CustomerId" ControlID="lblCustomerId" PropertyName="Text" />
</FilterParameters>
</asp:SqlDataSource>
</div>
</form>
Second Page:C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
lblCustomerId.Text = Decrypt(HttpUtility.UrlDecode(Request.QueryString["cId"]));
}
}
private string Decrypt(string cipherText)
{
string EncryptionKey = "MAKV2SPBNI99212";
cipherText = cipherText.Replace(" ", "+");
byte[] cipherBytes = Convert.FromBase64String(cipherText);
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.CreateDecryptor(), CryptoStreamMode.Write))
{
cs.Write(cipherBytes, 0, cipherBytes.Length);
cs.Close();
}
cipherText = Encoding.Unicode.GetString(ms.ToArray());
}
}
return cipherText;
}
Screenshot
