Silverlight / WPF - insert data into a atable using listview

Asked By newnw weer
21-Jun-10 08:48 PM

 

Hi ,

 

I have a listview with multiple columns, I want to insert all  data in that listview to a table using c# in WPF application.

 

Can anybody help me to do this.

Thanks.

  Goniey N replied to newnw weer
22-Jun-10 07:00 AM

private void BindDetails(string sortExpression)
{
sortExpression = sortExpression.Replace("Ascending", "ASC");
using (SqlConnection conn = new SqlConnection(_connStr))
{
conn.Open();
using (SqlDataAdapter dAd = new SqlDataAdapter("select * from Details order by Name", conn))
{
DataTable dTable = new DataTable();
dAd.Fill(dTable);
// Sort now
dTable.DefaultView.Sort = sortExpression;
// Bind data now
ListView1.DataSource = dTable;
ListView1.DataBind();
}
conn.Close();
}
}


protected void InsertListViewItem(object sender, ListViewInsertEventArgs e)
{
ListViewItem item = e.Item;
TextBox tName = (TextBox) item.FindControl("txtName");
TextBox tAddress = (TextBox)item.FindControl("txtAddress");
TextBox tPhone = (TextBox)item.FindControl("txtPhone");
// insert records into database
using (SqlConnection conn = new SqlConnection(_connStr))
{
string Sql = "insert into Details (Name, Address, Phone) values " +
" (@Name, @Address, @Phone)";
conn.Open();
using (SqlCommand dCmd = new SqlCommand(Sql, conn))
{
dCmd.Parameters.AddWithValue("@Name", tName.Text.Trim());
dCmd.Parameters.AddWithValue("@Address", tAddress.Text.Trim());
dCmd.Parameters.AddWithValue("@Phone", tPhone.Text.Trim());
dCmd.ExecuteNonQuery();
}
conn.Close();
}
lblMessage.Text = "Records Inserted Successfully.";
// Rebind the details
BindDetails("Name ASC");
}





//Using This Way You Can Insert Your Data in The ListView........

  Venkat K replied to newnw weer
22-Jun-10 10:43 AM

You can insert data into a dataset from the listview control and upate to the databse.

 

Check this article:

http://www.codeguru.com/vb/controls/vbnet_controls/listview/article.php/c3979/How-to-Fill-a-ListView-with-any-ADONet-Dataset.htm

 

Thanks

Create New Account
help
silverlight and wpf difference if one person has gain master in silverlight than wiil this help him in learning wpf Hi Malik, WPF has a more advanced and mature XAML support than Silverlight. Silverlight used to be called (WPF / E) and is a subset of the WPF XAML design well and other items. WPF is hardware accelerated and supports things like GPU shaders which Silverlight 2 does not. Silverlight 2 does have the VisualStateManager inside Blend 2, which I think WPF needs an add on and a tweak to work. I think that is the only case where Silverlight 2 XAML was / is slightly ahead of WPF's. Here is a link on XAML us / library / cc917841(VS.95).aspx Here is a good article on MSNMAG about designing Silverlight / WPF apps together and sharing code: http: / / msdn.microsoft.com / en-us / magazine / cc895632.aspx
View HTML files in silverlight Silverlight / WPF hi. . how to View HTML files in silverlight? via silverlight how to disable the right click option in html files? i.e)SL html viewer no, status = no, menubar = no, resizable = yes"); } } } Create New Account keywords: View, HTML, files, in, silverlight description: p style = border:0px;margin-bottom: 18px; border-image: initial; outline-width: 0px; outline
SilverLight What is SilverLight, its concept, why to use it and how to use it What is Silverlight? Silverlight is a new cross-browser, cross-platform implementation of the .NET Framework for building and browsers, including Microsoft Internet Explorer, Mozilla Firefox, Apple Safari, Opera. The plugin required to run Silverlight is very small in size hence gets installed very quickly. It is combination of different platform that allows you to select tools and the programming language you want to use. Silverlight integrates seamlessly with your existing Javascript and ASP.NET AJAX code to complement functionality which you have already created. Silverlight aims to compete with Adobe Flash and the presentation components of Ajax . It also competes with Sun Microsystems' JavaFX, which was launched a few days after Silverlight. Currently there are 2 versions of Silverlight: Silverlight 1.0 : Silverlight 1.0 consists of
Silverlight What is the purpose of Silverlight? Why it is used? How can I use silverlight in my application? Any simple web example of silverlight with VS 2005 and .Net Framework 2.0 (not the Hellow world Application). ? I want to start with Silverlight and I am very new to Silverlight. What is Silverlight? Microsoft Silverlight is a web browser plugin that provides support for rich internet applications such as animation
Framework " / > Hallo, ich will alle selektierten Eintr?ge in einem ListView in eine Liste ?bernehmen. ListViewItem listViewItem; listViewItem = new ListViewItem(); listViewItem.Text = "Eintrag 1"; listView1.Items.Add(listViewItem); listViewItem = new ListViewItem(); listViewItem.Text = "Eintrag 2"; listView1.Items.Add(listViewItem); List<ListViewItem> listItem = new List<ListViewItem> (); listItem