Monday, October 29, 2012

CellEditingTemplate in XAML

CellEditingTemplate in XAML

I have created a datagrid in silverlight having all textboxes(using CellEditingTemplate)..enter image description here

On click of save button i want to insert data of textboxes present in rows datagrid into database. How could I achieve this??

Answers & Comments...

Answer: 1

First of All you should create your View Model classes.

public class Person  {   public int ID {get;set;}   public string Name {get;set;}   public string Address {get;set;}   public int Age {get;set;} } 

then you create Observable Collection of this class and bind grid item source to it. in your template bind each column to it's property in the Person.

when you press save button in code behind you should call commit edit of the grid and then all of your data will be reflected to your observableCollection ... you can then save your data to db.

by : Emad Meladhttp://stackoverflow.com/users/1780589

Answer: 2

I solved it using

 TextBox txt = new TextBox();     txt = this.dtgrd.Columns[0].GetCellContent(lst_str[0]) as TextBox; 

It fetched the textbox inserted in following code and hence fetched the value stored in textbox..`

<sdk:DataGridTemplateColumn Header="ID" Width="*">                     <sdk:DataGridTemplateColumn.CellEditingTemplate>                         <DataTemplate>                             <TextBox Name="txt_ID"></TextBox>                         </DataTemplate>                     </sdk:DataGridTemplateColumn.CellEditingTemplate>                 </sdk:DataGridTemplateColumn> 

Now fetched value could be easily stored using List.

by : maatuhttp://stackoverflow.com/users/1759202




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog