I created a list of attendance in xaml with 3 tables.
1. The first table is the date that I put in the picker.
2. The second table is the name of the students that I put in the collectionview along with a picker containing 4 options.
3. The third table is attendance, which is stored in the database.
this is an example of c# ..
using AdmKelas.Models; using System; using System.ComponentModel; using Xamarin.Forms; using Xamarin.Forms.Xaml; using System.Collections.Generic; using System.Linq; namespace AdmKelas.Halaman { [DesignTimeVisible(false)] [XamlCompilation(XamlCompilationOptions.Compile)] public partial class EditAbsen : ContentPage { public EditAbsen() { InitializeComponent(); } protected override async void OnAppearing() { List<Siswa> sis = await App.Dtsekolah.GetSiswaAsync(); daftarSiswa.ItemsSource = sis; List<Kalpen> kal = await App.Dtsekolah.GetKalpenAsync(); tglKalpen.ItemsSource = kal; base.OnAppearing(); } async void SimpanData(object sender, EventArgs e) { var absen = (Absen)BindingContext; await DisplayAlert("Sukses!", "Data tersimpan", "Ok"); await App.Dtsekolah.SaveAbsenAsync(absen); await Navigation.PopAsync(); } async void HapusData(object sender, EventArgs e) { var result = await DisplayAlert("Peringatan!", "Data absen ini akan dihapus?", "Ya", "Batal"); if (result == true) { var absen = (Absen)BindingContext; await App.Dtsekolah.DeleteAbsenAsync(absen); await Navigation.PopAsync(); } else { return; } } } }
code xaml.
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:abstractions="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin" xmlns:local="clr-namespace:AdmKelas.CS" NavigationPage.HasNavigationBar="False" x:Class="AdmKelas.Halaman.EditAbsen"> <ContentPage.Content> <StackLayout> <Grid Margin="20,20,20,0" HeightRequest="120"> <!--<Entry x:Name="en1" IsVisible="false" Text="{Binding HariAbsen}"/> SelectedIndexChanged="Pick"--> <Frame Style="{StaticResource FrameBox}"> <local:CustomPicker Style="{StaticResource pickr}" Title="Tanggal" x:Name="tglKalpen" SelectedItem="{Binding HariAbsen}" ItemDisplayBinding="{Binding Tanggal, StringFormat='{0:dddd, dd MMMM yyyy}'}" HorizontalOptions="Center"> </local:CustomPicker> </Frame> <Label Text=" calendar-alt Tanggal " Style="{StaticResource LabelFrame}" HorizontalOptions="Center" FontSize="16"/> </Grid> <CollectionView x:Name="daftarSiswa" Margin="20,0,20,20" SelectionMode="None" ItemsLayout="VerticalGrid,2" HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand" EmptyView="Belum ada data yang ditampilkan. Anda harus memasukan data terlebih dahulu dengan mengabsen siswa sesuai tanggal."> <CollectionView.ItemTemplate> <DataTemplate> <StackLayout> <BoxView BackgroundColor="Black" Opacity="0.1" HeightRequest="1"/> <Grid ColumnDefinitions="0.7*,*" Padding="6"> <Grid Grid.Column="0"> <BoxView HeightRequest="1" HorizontalOptions="StartAndExpand" WidthRequest="1" Color="Goldenrod"/> <Grid HorizontalOptions="CenterAndExpand"> <abstractions:CircleImage Source="{Binding FotoSiswa}" Aspect="AspectFill" HeightRequest="60" WidthRequest="60" BorderColor="Goldenrod" BorderThickness="1" Margin="6" /> <Label Text="{Binding NamaKecil}" BackgroundColor="Black" VerticalOptions="Center" HorizontalOptions="EndAndExpand" TextColor="gold" FontSize="12" Padding="5,0,5,0" FontAttributes="Bold" Margin="10,0,0,-50"/> </Grid> </Grid> <Grid Grid.Column="1" HorizontalOptions="CenterAndExpand"> <local:CustomPicker Style="{StaticResource pickr}" Title="Absen" SelectedItem="{Binding CekList}"> <local:CustomPicker.ItemsSource> <x:Array Type="{x:Type x:String}"> <x:String>Hadir</x:String> <x:String>Sakit</x:String> <x:String>Izin</x:String> <x:String>Alpa</x:String> </x:Array> </local:CustomPicker.ItemsSource> </local:CustomPicker> <!--<RadioButton Text="Hadir" /> <RadioButton Text="Sakit"/> <RadioButton Text="Izin"/> <RadioButton Text="Alpa"/>--> </Grid> </Grid> </StackLayout> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> <BoxView BackgroundColor="Transparent" HeightRequest="1" Margin="-10" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/> <AbsoluteLayout> <StackLayout AbsoluteLayout.LayoutBounds="0,1,1,60" AbsoluteLayout.LayoutFlags="XProportional,YProportional,WidthProportional"> <StackLayout Orientation="Horizontal" Padding="8" BackgroundColor="#2196F3"> <Button Style="{StaticResource butn}" Text="times-circle" BackgroundColor="#EC2B4F" TextColor="AliceBlue" Clicked="HapusData" /> <Button Style="{StaticResource butn}" Text="check-circle" BackgroundColor="#7DDA49" TextColor="#0A402C" Clicked="SimpanData"/> </StackLayout> </StackLayout> </AbsoluteLayout> </StackLayout> </ContentPage.Content> </ContentPage>
how to write code behind the xaml to enter data into the third table?