среда, 27 октября 2010 г.

Definition list display table-like


dl
 {
 display: block;
 }

dt
 {
 clear:   left;
 display:  block;
 font-weight: bold;
 float:   left;
 width:   125px;
 }

dd
 {
 clear:   right;
 display:  block;
 white-space: nowrap;
 }

четверг, 21 октября 2010 г.

LINQ let Keyword (How did I miss that)


This is strange, because I've been working with LINQ for almost 2 years since (March 2006 CTP), and I've never noticed the new keyword "let" which is used inside LINQ queries to create temporarily variables.
check this out
var list = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var query = from i in list
let j = i + 2
let k = j * j
select new { i, j, k };
As you can see the let keyword was used to create two new temp variables (j, k) which their values were calculated inside the query.
Looks nice, doesn't it

воскресенье, 17 октября 2010 г.

How to Use ASP.NET ListView & DataPager

The DataPager control is used to page data and to display navigation controls for data-bound controls that implement the IPageableItemContainer interface.
A DataPager control can be associated to the data-bound control by using the PagedControlID property. Alternatively, the DataPager control can be placed inside the data-bound control hierarchy.
DataPager control will display navigation controls by adding the pager fields to the control. DataPager supports following types of pager fields. http://www.beansoftware.com/ASP.NET-Tutorials/ListView-DataPager.aspx

вторник, 5 октября 2010 г.

Silverlight get selected row data in DataGrid


The way I'd prefer to do this would be to bind IsChecked to a property of objects assigned to the ItemsSource. But here I'll show you the hard way to do it
(Edit: Actually the following is over complicated for this scenario but I'll leave it here for now, see edits after)
First you need one of my VisualTreeEnumeration extension methods:-
public static class VisualTreeEnumeration
{

    public static IEnumerable<DependencyObject> Ancestors(this DependencyObject root)
    {
        DependencyObject current = VisualTreeHelper.GetParent(root);
        while (current != null)
        {
            yield return current;
            current = VisualTreeHelper.GetParent(current);
        }
    }
}
Now in my testing I've just added a ListBox with the name lstOutput to my Xaml. Now add the following couple of event handlers to you UserControl :-
    private void rdbIndataGrid_Checked(object sender, RoutedEventArgs e)
    {
        DataGridRow row = ((DependencyObject)sender).Ancestors().OfType<DataGridRow>().FirstOrDefault();
        if (row != null)
            lstOutput.Items.Add(String.Format("Checked: {0}", row.DataContext));
    }

    private void rdbIndataGrid_Unchecked(object sender, RoutedEventArgs e)
    {
        DataGridRow row = ((DependencyObject)sender).Ancestors().OfType<DataGridRow>().FirstOrDefault();
        if (row != null)
            lstOutput.Items.Add(String.Format("Unchecked: {0}", row.DataContext));
    }
and finally tweak the Radio button Xaml like so:-
<RadioButton x:Name="rdbIndataGrid" IsChecked="false" GroupName="myGroup"
    Checked="rdbIndataGrid_Checked" Unchecked="rdbIndataGrid_Unchecked"  />
(One of the neat things about Xaml wiring up events is that it works even when the elements are part of a Template).
You'll note that in the event handlers I'm walking up the visual tree from the sending RadioButton to find the containing DataGridRow. The DataGridRow is the object that its DataContext set to the object being rendered by that row. In your own code you could cast the data context value to the correct type and from there access other data about the row.
Edit
Actually in most ordinary cases you don't need to hunt down the owning DataGridRow object accessing the DataContext property of the sending RadioButton is sufficient:-
    private void rdbIndataGrid_Checked(object sender, RoutedEventArgs e)
    {
        object myData = ((FrameworkElement)sender).DataContext;

        if (myData != null)
            lstOutput.Items.Add(String.Format("Checked: {0}", myData));
    }

    private void rdbIndataGrid_Unchecked(object sender, RoutedEventArgs e)
    {
        object myData = ((FrameworkElement)sender).DataContext;
        if (myData != null)
            lstOutput.Items.Add(String.Format("Unchecked: {0}", myData));
    }
Hence you can dispense with the Ancestors extension method. However in more complex cases where the DataContext have been changed the original "over-complicated" approach may be needed.