Binding a list to an asp.net gridview
I am binding a list to an asp.net gridview control which displays different profiles(having attributes such as name, password,description,date etc.)
now the problem lies anyone can visiting the page is able to view all profiles but I want no one to view the "PASSWORD" of any of the profiles You may need the code for it:
Array k1 = yourlist1.ToArray();
business.clsprofiles obj = new business.clsprofiles();
List<business.clsprofilesprp> objprp = new List<business.clsprofilesprp>();
for (Int32 i = 0; i < k1.Length; i++)
{
Int32开发者_运维技巧 z = Convert.ToInt32(k1.GetValue(i));
objprp.AddRange(obj.fnd_profiles(z));
}
GridView2.DataSource = objprp;
GridView2.DataBind();
con.Close();
You probably just need to hide the gridview column:
GridView2.Columns[0].Visible = false;
...replacing 0 with the index of the column. This is a fairly haphazard way of treating the problem however, as a change to the underlying class may expose the password column. A better approach would entail:
- Not storing the passwords in plain text at all.
- Not pulling the passwords into the business object in the first place if you don't need them.
- Inheriting the underlying business object class and changing the access to the password column.
- Manually specifying your columns rather than using AutoGenerateColumns
精彩评论