Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In Silverlight grid view I enter some values in columns. When I click the update button the data will be update in database.
Please give me the source code.
Posted
Updated 5-Aug-10 18:51pm
v3
Comments
Kunal Chowdhury «IN» 14-Aug-10 23:41pm    
Reason for deleting one of your comment: It had only blank line break.

Well, it's a very basic thing that you are trying to do. If you have tried then surely you would had succeeded in doing it as there are lots of articles and tutorials too explaining the same.

But, you havn't tried. Instead you demand code here. 'Give me...' Oops! not the right way....

Here is what is expected by enquirers:
1. TRY first what you want to do!
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this


For now,
Use Update command, trap that in ItemCommand and then based on the row that you need, use the values of it and update it in DB. Try now!
 
Share this answer
 
Comments
sampath55 5-Aug-10 15:24pm    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;


namespace silverlightgridview
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
List<employee> employeelist = new List<employee>();
employeelist.Add(new Employee { FirstName = "John", LastName = "Smith", Salary = 55000, StartDate = new DateTime(2003, 10, 13), IsVested = true });
employeelist.Add(new Employee { FirstName = "Jim", LastName = "Smith", Salary = 55000, StartDate = new DateTime(2006, 1, 13), IsVested = true });
employeelist.Add(new Employee { FirstName = "Brady", LastName = "Johnson", Salary = 70000, StartDate = new DateTime(1999, 4, 20), IsVested = false });
employeelist.Add(new Employee { FirstName = "Brenda", LastName = "Smith", Salary = 65000, StartDate = new DateTime(2000, 12, 1), IsVested = false });
employeelist.Add(new Employee { FirstName = "Bob", LastName = "Richards", Salary = 50000, StartDate = new DateTime(2004, 11, 13), IsVested = false });
employeelist.Add(new Employee { FirstName = "Sue", LastName = "Doe", Salary = 85000, StartDate = new DateTime(1990, 3, 2), IsVested = true });

CreateColumns();

grdDisplay.ItemsSource = employeelist;
}
private void CreateColumns()
{
//text columns
DataGridTextColumn textColumn1 = new DataGridTextColumn();
textColumn1.Header = "First Name";
textColumn1.Binding = new Binding("FirstName");
textColumn1.Width = new DataGridLength(100);
grdDisplay.Columns.Add(textColumn1);

DataGridTextColumn textColumn2 = new DataGridTextColumn();
textColumn2.Header = "Last Name";
textColumn2.Binding = new Binding("LastName");
grdDisplay.Columns.Add(textColumn2);

DataGridTextColumn textColumn4 = new DataGridTextColumn();
textColumn4.Header = "Salary";
textColumn4.Binding = new Binding("Salary");
grdDisplay.Columns.Add(textColumn4);

DataGridCheckBoxColumn checkBoxColumn = new DataGridCheckBoxColumn();
checkBoxColumn.Header = "Is Vested";
checkBoxColumn.Binding = new Binding("IsVested");
checkBoxColumn.Width = new DataGridLength(75);
grdDisplay.Columns.Add(checkBoxColumn);

DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();
templateColumn.Header = "Start Date";
templateColumn.CellTemplate = (DataTemplate)Resources["datetemplate"];
templateColumn.Width = new DataGridLength(100);
grdDisplay.Columns.Add(templateColumn);
}
public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public decimal Salary { get; set; }
public DateTime StartDate { get; set; }
public bool IsVested { get; set; }
}
}
}
sampath55 5-Aug-10 15:25pm    
i try it but the browser is notshowing the data grid
sampath55 5-Aug-10 15:26pm    
i Want solution in silver light
No one will give you the source code to achieve this task.
Silverlight does not support Ado.Net directly, so you will need to use either the Entity Framework or Web services to update your database.
 
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