J
James
I've got a GridView control on a simple web page in ASP.net 3.5.
I've an Array of Employees. An Employee has First Name, Last Name, IsActiveEmployee etc
My GridView control is Bounded to the Array: DataSource = myarray, gridview1.DataBind()
I have template column with holds a link button
when the button is clicked, I've got a method which will set the selected
employee "IsActiveEmployee" flag to false.
My problem is that when the page reloads and binds, the array returned is NOT change - it is the same array.
Can somebody please help?
My Page file is defined as:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.GridView1.DataSource = Utils.GetGlobalListOfOutlookContacts();
this.GridView1.DataBind();
}
protected void MarkAsPrivate(int id)
{
int tmpId = id;
Utils.MarkPrivate(tmpId);
}
protected void LinkButton1_Command(object sender, CommandEventArgs e)
{
object o = e.CommandArgument;
String s = Convert.ToString(o);
int tmpId = Convert.ToInt32(s);
Utils.MarkPrivate(tmpId);
}
}
My Utils file is defined as:
public static class Utils
{
public static readonly String SPACE = " ";
private static List<AContact> GlobalListOfOutLookContacts = new List<AContact>()
{
new AContact {ContactId=1388, FirstName = "Kriss", LastName = "Bellamy", Company="Oracle", E_mail="(e-mail address removed)", Location="5100 Town Cntr Circle"},
new AContact {ContactId=1389, FirstName = "Ada", LastName = "peterson", Company="Oracle", E_mail="(e-mail address removed)", Location="1364 Park Street"},
new AContact {ContactId=1390, FirstName = "Paul", LastName = "wellby", Company="Oracle", E_mail="(e-mail address removed)", Location="54 State St Suite 1000"},
new AContact {ContactId=1391, FirstName = "Damien", LastName = "Johnson", Company="Google", E_mail="(e-mail address removed)", Location="1 Atlon Court Paris"}
};
public static List<AContact> GetGlobalListOfOutlookContacts()
{
var ContactList = from contacts in GlobalListOfOutLookContacts where contacts.IsPrivateContact != true select contacts;
List<AContact> retVal = new List<AContact>();
foreach (AContact c in ContactList)
{
retVal.Add(c);
}
return retVal;
}
public static void MarkPrivate(int cid)
{
var ContactList = (from contacts in GlobalListOfOutLookContacts where (contacts.ContactId == cid) select contacts).First();
ContactList.IsPrivateContact = true;
}
}
I've an Array of Employees. An Employee has First Name, Last Name, IsActiveEmployee etc
My GridView control is Bounded to the Array: DataSource = myarray, gridview1.DataBind()
I have template column with holds a link button
when the button is clicked, I've got a method which will set the selected
employee "IsActiveEmployee" flag to false.
My problem is that when the page reloads and binds, the array returned is NOT change - it is the same array.
Can somebody please help?
My Page file is defined as:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.GridView1.DataSource = Utils.GetGlobalListOfOutlookContacts();
this.GridView1.DataBind();
}
protected void MarkAsPrivate(int id)
{
int tmpId = id;
Utils.MarkPrivate(tmpId);
}
protected void LinkButton1_Command(object sender, CommandEventArgs e)
{
object o = e.CommandArgument;
String s = Convert.ToString(o);
int tmpId = Convert.ToInt32(s);
Utils.MarkPrivate(tmpId);
}
}
My Utils file is defined as:
public static class Utils
{
public static readonly String SPACE = " ";
private static List<AContact> GlobalListOfOutLookContacts = new List<AContact>()
{
new AContact {ContactId=1388, FirstName = "Kriss", LastName = "Bellamy", Company="Oracle", E_mail="(e-mail address removed)", Location="5100 Town Cntr Circle"},
new AContact {ContactId=1389, FirstName = "Ada", LastName = "peterson", Company="Oracle", E_mail="(e-mail address removed)", Location="1364 Park Street"},
new AContact {ContactId=1390, FirstName = "Paul", LastName = "wellby", Company="Oracle", E_mail="(e-mail address removed)", Location="54 State St Suite 1000"},
new AContact {ContactId=1391, FirstName = "Damien", LastName = "Johnson", Company="Google", E_mail="(e-mail address removed)", Location="1 Atlon Court Paris"}
};
public static List<AContact> GetGlobalListOfOutlookContacts()
{
var ContactList = from contacts in GlobalListOfOutLookContacts where contacts.IsPrivateContact != true select contacts;
List<AContact> retVal = new List<AContact>();
foreach (AContact c in ContactList)
{
retVal.Add(c);
}
return retVal;
}
public static void MarkPrivate(int cid)
{
var ContactList = (from contacts in GlobalListOfOutLookContacts where (contacts.ContactId == cid) select contacts).First();
ContactList.IsPrivateContact = true;
}
}