I am trying this but getting no success
var v=ds.Table[0].AsEnumerable().Where<DataRow>(r=>r.Field<int>("productID")==23);
GridView1.DataSource=v;
GridView1.DataBind();
网格显示,只有1个排向罗尔·哈斯罗尔,但我期望有1个排,有产品信息。
I am trying this but getting no success
var v=ds.Table[0].AsEnumerable().Where<DataRow>(r=>r.Field<int>("productID")==23);
GridView1.DataSource=v;
GridView1.DataBind();
网格显示,只有1个排向罗尔·哈斯罗尔,但我期望有1个排,有产品信息。
我认为,你应当尝试使用<条码>。 表格
ds.Table[0].AsEnumerable().Where<DataRow>(r=>r.Field<int>("productID")==23).CopyToDataTable();
When you convert it to an Enumerable the filtered list has no identifiers for say ProductID
hence the grid would fail to map the column and fail.
也可选择使用<条码>AsDataView()而不是<条码>CopyToDataTable(<>>)。
A more detailed explanation can found Binding DataRows
Databinding is controlled by the ListBindingHelper and TypeDescriptor classes. When you bind to a list, the ListBindingHelper.GetListItemProperties method is called to get the columns in the list. If the list implements the ITypedList interface, its GetItemProperties method is called. Otherwise, it will use TypeDescriptor to get the properties of the first item in the list. (this uses reflection)
The DataView class (which DataTable also binds through, using IListSource) implements ITypedList and returns DataColumnPropertyDescriptors that expose the columns in the table. This is why you can bind to a DataView or DataTable and see columns. However, when you bind to a List, there is no ITypedList that can return the columns as properties. It therefore falls back on reflection and shows the physical properties of the DataRow class.
引证。
var results = from myRow in ds.Table[0].Rows
where myRow.Field<int>("productID") == 23
select myRow;
这应该给你看望的几句。
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...