se come me diventare sempre pià prigri e anche un FindControl diventa faticoso, apprezzere sicuramente i vari xxxDataSource.
ma quando avete a che fare con il Profile?
bhe realizziamone uno ad hoc, così non ci perdiamo nessun automatismo
using System;
using System.Web;
using System.Collections.ObjectModel;
using System.Web.UI;
using System.Web.Profile;
using System.Collections;
namespace MyCustomControl
{
public class ProfileDataSourceControl : DataSourceControl
{
protected override DataSourceView GetView(string viewName)
{
return new ProfileView(this, viewName);
}
}
public class ProfileView : DataSourceView
{
private ProfileBase _profile = null;
private HttpContext _context = null;
public ProfileView(IDataSource owner, string viewName): base(owner, viewName)
{
_context = HttpContext.Current;
if (_context == null)
{
throw new ApplicationException("Impossibile ricavare il contesto della chiamata");
}
_profile = _context.Profile;
}
protected override System.Collections.IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
{
return new Collection<profilebase />() { _profile };
}
protected override int ExecuteInsert(IDictionary values)
{
_profile = ProfileBase.Create(_context.User.Identity.Name, _context.User.Identity.IsAuthenticated);
foreach (DictionaryEntry item in values)
{
_profile[item.Key.ToString()] = item.Value;
}
_profile.Save();
return 0;
}
protected override int ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)
{
foreach (DictionaryEntry item in values)
{
_profile[item.Key.ToString()] = values[item.Key.ToString()];
}
_profile.Save();
return 0;
}
protected override int ExecuteDelete(IDictionary keys, IDictionary oldValues)
{
foreach (DictionaryEntry item in oldValues)
{
_profile[item.Key.ToString()] = null;
}
_profile.Save();
return 0;
}
}
}
nel lab trovare altri xxxDataSource creati da Cristian
Per inserire un commento, devi avere un account.
Fai il login e torna a questa pagina, oppure registrati alla nostra community.
Nella stessa categoria
- Modificare il controllo TreeView, il 2 dicembre 2008 alle 19:27
- Perfezioniamo il ProfileDataSorce, il 13 ottobre 2008 alle 11:14
- TrueSpace 7 gratuito, il 24 luglio 2008 alle 10:59
- adesso dico la mia sull'Iphone, il 22 luglio 2008 alle 10:33
- Come tutto ebbe inizio, il 21 luglio 2008 alle 09:22
I più letti del mese