First I needed to refresh. First hit got me here, with the answer. A simple call to GridView1.DataBind(); will cause the grid to refresh.
Then I need to handle exceptions. This is done by setting e.ExceptionHandled=true in a OnUpdated, OnDeleted etc func with the signature:
protected void OnUpdated(object sender, ObjectDataSourceStatusEventArgs e).
Then I needed to set whats the key to be passed into the DeleteMethod. This is done by setting the DataKeyNames on the grid
mandag 24. august 2009
torsdag 20. august 2009
Using a ObjectDataSource that takes constructors
is simply done by creating the object in the OnObjectCreating event, thanks to this link.
protected void ObjectDataSource1_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
{
BLL bll = new BLL("arg1",100);
e.ObjectInstance = bll;
}
<asp:ObjectDataSource ID='ObjectDataSource1' runat='server' SelectMethod='GetData' TypeName='BLL' OnObjectCreating='ObjectDataSource1_ObjectCreating'></asp:ObjectDataSource>protected void ObjectDataSource1_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
{
BLL bll = new BLL("arg1",100);
e.ObjectInstance = bll;
}
onsdag 19. august 2009
Getting a property value from reflection
Needed to get a value of a property I don't know runtime. This is what I ended up with:
// get the property via reflectionvar v = person.GetType().GetProperty("NameOfProperty");
v.GetValue(person, null).ToString();Merge xml files with XDocument
Quick answer to this link at stackoverflow:
var MyDoc = XDocument.Load("File1.xml");
MyDoc.Root.Add(XDocument.Load("File2.xml").Root.Elements());
var MyDoc = XDocument.Load("File1.xml");
MyDoc.Root.Add(XDocument.Load("File2.xml").Root.Elements());
fredag 14. august 2009
RegEx - I don't need to learn it!
Thanks to this tool I can skip learning the regex syntax again. :-)
torsdag 13. august 2009
Object Copy Function
Well, I guess I knew, but still made a search on how I got the shallow copy when I needed a deep copy. I found this post explaining my options.
Binding ComboBox to enum
Wow.. That did take me a lot of googling to figure out! I finally I ended up with the sln from this post. Key findings is that you can't use the enum as an ItemsSource (not a IEnumerable), so we need to wrap it in a collection class. The link shows a nice generic EnumCollection.
fredag 7. august 2009
PagedCollectionView's filter does not refilter on modified Items
So the PagedCollectionView can't be used out of the box for live filtering. At least this is what I know now. Maybe an answer shows up here
Syntax of custom comparer in OrderBy
Ok, so the Parameter Info says: Func
And I should write:
var comparer = new MyComparer();
Users.OrderBy(x => x.Name, comparer).ToList();
public class MyComparer : IComparer<Object>
torsdag 6. august 2009
Setting binding from code
Forgot this one again:
var b = new Binding("Data"); // Property on datacontext
TheGrid.SetBinding(DataGrid.ItemsSourceProperty, b);Lambda syntax for eventhandlers
I needed to look up this again. Hopfully it's the last time...
Thanks to this link
var button = new Button();
button.Click += (s, e) =>
{ button.Content = "I'm Clicked";};
Thanks to this link
onsdag 5. august 2009
Convert a List to an ObservableCollection
I could do this by using a foreach loop, but I learned some shorter syntax:
Thanks to this thread
var list = new List<User> {new User {Name = "Name"}};
var oc = new ObservableCollection<User>();
list.ForEach(oc.Add); // list.ForEach(x => oc.Add(x)); Quit googleing, start using your brain!
I find myself googling for the same thing over and over. So instead of learn and remember, I do copy paste. To help me remember, I'll write everything a learn (or relearn) in this blog. Hopfully it should be something every day!
Results to be entered!
Abonner på:
Kommentarer (Atom)