I use the ListView pretty much exclusively for all my databinding needs, because, well, it does everything. One of the common things I do over and over in my backend is something like this:
myListView.DataSource = myDataSource;
myListView.DataBind();
I wanted to basically set the datasource, and bind it all in one line of code (because I’m lazy). So I wrote up this extension method:
public static ListView QuickDataBind(this ListView myListView, object myDataSource)
{
myListView.DataSource = myDataSource;
myListView.DataBind();
return myListView;
}
Now whenever I want to set a datasource and bind it, I simply write:
myListView.QuickDataBind(myDataSource);
and it’s done!
Just a little extension I thought might be useful for “aps.netters” who use the ListView a lot, and databind from the code-behind.