你创建了一个ASP.net应用程序,该程序使用DataGrid控件显示已存储的产品列表信息。产品数据库存储在一个名为TestKingDB的SQL Server数据库中。每个产品使用名为ProductID的数值字段标识,每种产品都有一个名为ProductName的字符字段。你编写ADO.net代码,使用SqlDataAdapter对象和SqlCommand对象通过调用存储过程从数据库中获取数据。你设置SqlCommand对象的CommandType属性为CommandTyp.StoredProcedure,CommandText属性为procProductList。你的代码,使用以ProductID字段降序排列的产品列表数据,成功填充了一个DataTable对象。你想使用数据以ProductName字段按字母顺序重新显示,你应该怎么做?(B) ( G. l8 y- I" U+ d1 y# b
A、更改SqlCommand对象的CommandType属性为CommandType.Text;
* R) ?. S' x9 m% P 更改SqlCommand对象的CommandText属性为如下代码: 4 { x; b4 m# u- M# Q8 t" x# |4 I
绑定DataGrid控件到DataTable对象;
6 g$ |. t3 q/ C) E B、在DataTable对象的基础上创建一个DataView对象;
1 s$ @( m7 R+ w( j 设置DataView对象的Sort属性为:“ProductName DESC”; , r. [- y- _' {9 S4 F" V8 B
绑定DataGrid控件到DataView对象; 7 h2 {6 o2 K6 ?: W& ?; `
要重新排序,不改变原来的显示顺序;可以用Dataview对象,它只改变内存中的数据排序;不改变数据源; 7 r7 x0 X2 c; b* i
C、设置DataGrid控件的AllowSorting属性为True;
& H/ |" h! [. V 设置DataGridColumn的SortExpression使用“ProductName DESC”显示ProductName; 4 O+ ]" G# O7 r* U. z) X
绑定DataGrid控件到DataTable对象; ! w& z% k- a' s) g3 y
D、设置DataTable对象的DisplayExpression属性为: y8 M1 A' O, A; }5 t
绑定DataGrid控件到DataTable对象; _+ { m$ [( s' l2 F' M
注:Sort属性:获取或设置 DataView 的一个或多个排序列以及排序顺序
5 V' Y8 g4 n, f% Z, Q! GAllowSorting属性:获取或设置一个值,该值指示是否可以通过单击列标头对网格进行重新排序。 ' M: ]8 ?6 o* b& D" M6 V/ C
DisplayExpression属性:获取或设置将返回一个值的表达式,该值用于表示用户界面中的该表
3 P/ Y) `! s1 G: D本题的根源是数据源的排序方式,A,C,D三项都不能实现本题目标。 |