Click here to Skip to main content
16,020,249 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So here is what I am trying to do on DataTextFormatString, I want to format it to encrypted but the only thing that is being encrypted is "{0}" and not the actual rows that it represents, please help.

What I have tried:

This the things that I have tried, but I know it has the wrong syntax. But I hope you get the idea on what I am trying to do...

HyperLinkField Age = new HyperLinkField();
Age.DataNavigateUrlFormatString = "./testpage.aspx?Id={0}";
Age.DataTextField = "Age";
Age.HeaderText = "Age";
Age.DataTextFormatString = Encryption.GetEncryption("{0}");
GridView1.Columns.Add(Age);


Encryption has the static method GetEncryption which is this:

public static string GetEncryption(string data)
    {
        return Convert.ToBase64String(EncryptString(data));
    }
Posted
Updated 12-Apr-18 0:18am
v2
Comments
F-ES Sitecore 12-Apr-18 4:38am    
First off, base64 encoding is not encryption.

Anyway, you'll need to alter the data as it is being bound using something like the row binding events

https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound(v=vs.110).aspx

As the item is bound you can change the text of the link to be the encoded version of itself.

1 solution

So, I followed your advise and this is my answer to my question,

I added a new column to the data set, named 'encrypted_age',

Then on the data table I processed the existing rows from column age, to be encrypted. I used the if rows is empty since I don't need a new row on the data set but to fill the new column with new row values.

After the column 'Encrpyted_Age' is filled, I used it to be displayed on the code behind GridView Column which is the HyperLinkField.

Thank you for helping me

ds.Tables[0].Columns.Add("Encrypted_Age", typeof(string));
           int i = 0;
           foreach (DataRow row in ds.Tables[0].Rows)
           {

               if (ds.Tables[0].Rows[i][3].ToString() == "")
               {
                   ds.Tables[0].Rows[i][3] = Crypto.GetEncryptedQueryString(row["age"].ToString());
               }
               i++;
           }

           ds.Tables[0].AcceptChanges();

           con.Close();

           HyperLinkField Age = new HyperLinkField();
           string[] dataNavigateUrlFields = { "Encrypted_Age" };

           Age.DataNavigateUrlFormatString = "./testpage.aspx?id={0}";
           Age.DataNavigateUrlFields = dataNavigateUrlFields;
           Age.DataTextField = "Encrypted_Age";
           Age.HeaderText = "Age";

           GridView1.Columns.Add(Age);

           GridView1.DataSource = ds;
           GridView1.DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900