如何在网格视图代码隐藏中应用我的静态方法? [英] How can I apply my static method in grid view codebehind?
本文介绍了如何在网格视图代码隐藏中应用我的静态方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以这就是我想对DataTextFormatString做的事情,我想将其格式化为加密但是唯一被加密的是{0}而不是它所代表的实际行,请帮忙。 />
我尝试了什么:
这是我试过的东西,但我知道它的语法错误。但是我希望你能理解我想要做的事情......
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);
加密有静态方法GetEncryption就是这样:
Encryption has the static method GetEncryption which is this:
public static string GetEncryption(string data)
{
return Convert.ToBase64String(EncryptString(data));
}
推荐答案
所以,我按照你的建议,这是我对我的问题的回答,
我在数据集中添加了一个新列,名为'encrypted_age',
然后在数据表上我处理了从列时代开始的现有行,以进行加密。我使用if行是空的,因为我不需要数据集上的新行,而是用新的行值填充新列。
列之后'Encrpyted_Age'已填充,我用它显示在GridView列后面的代码,即HyperLinkField。
感谢您帮助我
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();
这篇关于如何在网格视图代码隐藏中应用我的静态方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文