while a new row is adding in gridview, the data is binding only new rows. the old rows are not coming.
Data is coming from the profile properties.
Add new row command event is listed below
bool isUserAccountCreated = false;
UserProfile profilenew = new UserProfile();
if (e.CommandName == "AddNew")
{
TextBox txtEmailnew = (TextBox)grdUsers.FooterRow.FindControl("txtemail");
TextBox txtFirstNamenew = (TextBox)grdUsers.FooterRow.FindControl("txtfirstname");
TextBox txtLastNamenew = (TextBox)grdUsers.FooterRow.FindControl("txtLastname");
TextBox txtCompanyNamenew = (TextBox)grdUsers.FooterRow.FindControl("txtCompanyName");
TextBox txtCellphonenew = (TextBox)grdUsers.FooterRow.FindControl("txtPhoneNumber");
TextBox txtAccountNumber = (TextBox)grdUsers.FooterRow.FindControl("txtAccountNumber");
profilenew.Email = txtEmailnew.Text;
profilenew.First_Name = txtFirstNamenew.Text;
profilenew.Last_Name = txtLastNamenew.Text;
profilenew.CompanyName = txtCompanyNamenew.Text;
profilenew.CellPhone = txtCellphonenew.Text;
profilenew.AccountNumber = txtAccountNumber.Text;
if (MVRUtilityBO.isEmail(profilenew.Email))
{
MVRProvider.membershipUser = MVRProvider.GetUser(profilenew.Email);
if (MVRProvider.membershipUser == null)
{
using (TransactionScope ts = new TransactionScope())
{
CreateAccount(profilenew);
profilenew.UserId = MVRProvider.membershipUser.ProviderUserKey;
ts.Complete();
isUserAccountCreated = true;
}
if (isUserAccountCreated)
{
profilenew.PrimaryUserEmail = profilenew.Email;
_orderdetailsbo.CreatePrimaryUser(usersubscription, profilenew);
int merchLocid = (int)Session["merchLocid"];
_orderdetailsbo.InsertMerchLocAssignUser(profilenew, merchLocid);
BindUsersInformation(profilenew);
}
}
}
}
}
private void CreateAccount(UserProfile userProfile)
{
//Create User
userProfile.Password = "asdf1234";
string createStatus = MVRProvider.CreateUser(userProfile.Email, userProfile.Password, userProfile.Email, userProfile.SecurityQuetion, userProfile.SecurityAnswer);
//Create Profile
PrimaryUserProperties(userProfile);
}
private bool PrimaryUserProperties(UserProfile userProfile)
{
bool isUserProfileCreated = true;
MVRProvider.membershipUser = MVRProvider.GetUser(userProfile.Email);
if (MVRProvider.membershipUser != null)
{
userProfile.UserId = MVRProvider.membershipUser.ProviderUserKey;
CustomProfile profile = CustomProfile.GetProfile(userProfile.Email);
profile.ProfileProperties.First_Name = userProfile.First_Name;
profile.ProfileProperties.Last_Name = userProfile.Last_Name;
profile.ProfileProperties.CompanyName = userProfile.CompanyName;
profile.ProfileProperties.CellPhone = userProfile.CellPhone;
profile.ProfileProperties.AccountNumber = userProfile.AccountNumber;
profile.Save();
}
else
{
isUserProfileCreated = false;
}
return isUserProfileCreated;
}
public void BindUsersInformation(UserProfile profileNew)
{
int merchLocid = (int)Session["merchLocid"];
UserProfiles userprofiles = _orderdetailsbo.GetUsernamesByLocation(profileNew, merchLocid);
if (userprofiles.Count > 0)
{
var matchuserprofile = userprofiles.Where(x => x.Email.Equals(profileNew.Email))
.Select(x=>x);
bool isuserpresent = false;
foreach (var profiles in matchuserprofile)
{
isuserpresent = true;
}
if (!isuserpresent)
{
userprofiles.add(profileNew);
}
grdUsers.DataSource = userprofiles;
grdUsers.DataBind();
}
else
{
userprofiles.add(profileNew);
grdUsers.DataSource = userprofiles;
grdUsers.DataBind();
}
}