Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<ListView x:Name="list_1" ItemsSource="{Binding Persons}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                         <StackLayout Margin="1">
                            <Label Text="{Binding Name}"/>
                            <Label Text="{Binding Age}"/>
                        </StackLayout>

<button Text="Submit" Command="SaveCommand">

                        </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>









------------------------code behind------------------------------------


How to save with SaveCommand in code behind.

I want listview item save into sql database like Name and Age. and how to find listview label item in code behind.


using(sqlcon con=new sqlcon(connectionname))
{
using(sqlcom com= new sqlcommand("",con))
     {

sqlcom.parameter.addwithvalue("col_name",LabelName);

con.open();

      }
}


What I have tried:

I am new with xamarin form but i want to try learn with c#.
Posted
Updated 22-Mar-22 23:34pm
Comments
CHill60 23-Mar-22 5:25am    
Your question is not clear. Please use the "Improve question" link to add an explanation of your problem

1 solution

You can use the CommandParameter property to pass an object into the Execute(Object); command. In this case it sounds like you want to pass in the object which has been bound to the forms, something like:

C#
// WPF
<Button Command="SaveCommand" CommandParameter="{Binding}" />

// C#
public void Execute(object? parameter)
{
  var person = parameter as Person; // Cast to the appropriate object type

  // Use the properties
  person.Name;
  person.Age;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900