You must Sign In to post a response.
  • Category: ASP.NET

    How to populate data in a grid View using WPF in

    how to populate data in a grid View using WPF in

    please paste some sample code ..
  • #493806
    <Grid x:Name="Grid1">
    <ListView Name="ListViewEmployeeDetails" Margin="4,20,40,100" ItemTemplate="{DynamicResource EmployeeTemplate}" ItemsSource="{Binding Path=Table}">
    <GradientStop Color="Gray" Offset="0"/>
    <GridViewColumn Header="Employee ID" DisplayMemberBinding="{Binding Path=EmployeeID}"/>
    <GridViewColumn Header="First Name" DisplayMemberBinding="{Binding Path=FirstName}"/>
    <GridViewColumn Header="Last Name" DisplayMemberBinding="{Binding Path=LastName}"/>
    <GridViewColumn Header="BirthDate" DisplayMemberBinding="{Binding Path=BirthDate}"/>
    <GridViewColumn Header="City" DisplayMemberBinding="{Binding Path=City}"/>
    <GridViewColumn Header="Country" DisplayMemberBinding="{Binding Path=Country}"/>

    Here is .cs code:

    SqlConnection con = new SqlConnection();
    SqlDataAdapter ad = new SqlDataAdapter();
    SqlCommand cmd = new SqlCommand();
    String str = "SELECT EmployeeID, FirstName, LastName, BirthDate, City, Country FROM Employees";
    cmd.CommandText = str;
    ad.SelectCommand = cmd;
    con.ConnectionString = "Data Source =localhost; Initial Catalog=Northwind; Integrated Security=True";
    cmd.Connection = con;
    DataSet ds = new DataSet();
    ListViewEmployeeDetails.DataContext = ds.Tables[0].DefaultView;

    Note: Add two namespace.

    using System.Data.SqlClient;
    using System.Data;

    Thanks & Regards
    Manish Visa

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.