datagrid中的列数总是为零为什么? [英] Count of column in datagrid is always zero why?

查看:113
本文介绍了datagrid中的列数总是为零为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中使用一个数据网格,我需要对齐该数据网格的颜色。



DataGrid dgAccount = new DataGrid();

dgAccount .DataSource = dtaccount; // datatable

dgAccount .DataBind();



但这里的问题是我的数据网格中的列数为零。但数据存在于数据中。并且我能够显示那些数据,但列的数量为零。

有人对此有任何想法吗?

解决方案

试试如下

DataGrid dg = new DataGrid();



dg.Items.Count; //物品数量......即。行;

dg.Items [0] .Cells.Count; //该项目的列数


试试这个,



int columnCount =((DataTable)this.dataGrid.DataSource ).Columns.Count;

In my code am using one datagrid , I need to align the coloumns of that datagrid.

DataGrid dgAccount = new DataGrid();
dgAccount .DataSource = dtaccount; //datatable
dgAccount .DataBind();

But the problem here is am getting the count of columns in my datagrid as zero.But data is there in datable. And am able to display that data but the count of column is zero.
Anybody have any idea about this ?

解决方案

try as bellow
DataGrid dg = new DataGrid();

dg.Items.Count; //Number of Items...i.e. Rows;
dg.Items[0].Cells.Count; //Number of columns for that Items


Try this,

int columnCount = ((DataTable)this.dataGrid.DataSource).Columns.Count;


这篇关于datagrid中的列数总是为零为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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