0

I have a DataGrid which is binded using the following code,

C#

namespace SilverlightApplication1

{ public class data { public data(int rollno, bool present) { RollNo = rollno; Present = present; } public int RollNo { set; get; } public bool Present { set; get; } }

public class Data:List<data>
{
   public Data()
    {
       bool Present;
       int RollNo;
        int itemsCount = 20;
        for (int i = 0; i < itemsCount; i++)
        {
            Present= i % 2 == 0;
            RollNo = i;
            Add(new data(RollNo,Present));
        }
    }
}

}

XAML

<my:DataGrid x:Name="dgAttendance" AutoGenerateColumns="False" ItemSource="{StaticResource Data}">
    <my:DataGrid.Columns>
        <my:DataGridTextBoxColumn Header="Role No" Width="50" 
                                  DisplayMemberBinding="{Binding RollNo}" />
        <my:DataGridCheckBoxColumn Header="Present" 
                                   DisplayMemberBinding="{Binding Present}" />
    </my:DataGrid.Columns>
</my:DataGrid>

What I am supposed to add in <navigation:Page.Resources>

2 Answers 2

3

UPDATE

I followed something like this.

.CS :

List<data> DataList = new List<data>();
int itemsCount = 20;
for (int i = 0; i < itemsCount; i++)
{
     data NewData = new data();
     NewData.Present= i % 2 == 0;
     NewData.RollNo = i;
     DataList.Add(NewData);
}
TxtCompanyName.DataContext = e.Result;

XAML :

<my:DataGrid HorizontalAlignment="Stretch" Height="277" Margin="20,193,20,0" VerticalAlignment="Top" Width="799" ItemSource="{Binding}" AutoGenerateColumns="true"/>
1
  • 1
    u have just created a grid and not binded with data
    – Dhinesh
    Apr 7, 2014 at 4:12
3

Is Data your custom class? If yes, You need to include the namespace of Data class in this file.

4
  • I am sorry I didn't catch it, Data is a custom class
    – Dhinesh
    Apr 4, 2014 at 11:04
  • add using <Namespace_of_Data_class; at the beginning of Home.cs. Let me know if you have any issues :)
    – abmussani
    Apr 4, 2014 at 11:12
  • I have namespace but how to add in xaml? Is it like <local:Data x:Key="Data"/>
    – Dhinesh
    Apr 4, 2014 at 11:22
  • I am asking about <navigation:Page.Resources> <local:Data x:Key="Data" /> </navigation:Page.Resources>
    – Dhinesh
    Apr 4, 2014 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.