如何在Wpf应用程序中绑定数据网格我使用下面的代码导致错误和错误 [英] How To Bind A Datagrid In Wpf Application I Am Using Below Code Thats Causes Error And Error

查看:47
本文介绍了如何在Wpf应用程序中绑定数据网格我使用下面的代码导致错误和错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码导致错误和错误是

I am using below code thats causes error and error is

Error	4	'System.Windows.Controls.DataGrid' does not contain a definition for 'DataBind' and no extension method 'DataBind' accepting a first argument of type 'System.Windows.Controls.DataGrid' could be found (are you missing a using directive or an assembly reference?)



任何人都可以理清它


any one can sort out it

using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.QueryParsers;
using Lucene.Net.Search;
using Lucene.Net.Store;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows;
using Version = Lucene.Net.Util.Version;
namespace WpfApplication23
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow OnLoad(EventArgs e)
        {
           
            {
              GridView1.ItemsSource = Sample;
              GridView1.DataBind();
            }
        }

        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            var query = TextBox1.Text.Trim();

            var results = search(query);

            GridView1.DataSource = results;
            GridView1.DataBind();
        }
            DataTable Sample
        {
            get
            {
                var ds = new DataSet();
                SqlConnection con = new SqlConnection("Data Source=SHAHRUKH-PC\\SQLEXPRESS;Initial Catalog=info;User ID=sa;Password=sa@1234");
                SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Information", con);
                sda.Fill(ds);
                return ds.Tables[0];
            }
        }

推荐答案

如果您使用的是 DataGrid [ ^ ],然后你只需设置 ItemsSource [ ^ ]。没有像DataBind这样的方法被调用。
If you're using a DataGrid[^], then you just set the ItemsSource[^]. There's no method like DataBind to be called .


这篇关于如何在Wpf应用程序中绑定数据网格我使用下面的代码导致错误和错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆