急救!请大家都进来看看!!有关DATAGRID问题

jerrie_1 2005-09-18 03:44:37
请再帮我看看这段代码:
public class TStringGrid:System.Web .UI .WebControls .DataGrid
{
private int FixRow=8;
private int FixCol=5;
private DataTable Table;
public DataRowCollection Rows ;
public DataColumnCollection Columns ;

public TStringGrid():base()
{
}

public void Create()
{
for(int i=0;i<FixCol;i++)
{
System.Data .DataColumn column=new DataColumn ();
this.Columns.Add(column);
}
for(int j=0;j<FixRow;j++)
{
DataRow newrow=Table.NewRow ();
this.Rows.Add(newrow);
}
}
有没有问题?
但到引用时,就有问题:Label1.Text =sg.Columns .Count .ToString ();
问题提示:System.NullReferenceException: 未将对象引用设置到对象的实例
请问做如何修改啦?
...全文
175 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaowangtian1117 2005-09-19
  • 打赏
  • 举报
回复
往DataTable中加数据,不知道是不是你要的
DataTable tb=new DataTable();
DataRow dr;
tb.Columns.Add(new DataColumn("filename",typeof(string)));
tb.Columns.Add(new DataColumn("downid",typeof(Int32)));
tb.Columns.Add(new DataColumn("filetype",typeof(string)));
tb.Columns.Add(new DataColumn("upload",typeof(string)));
tb.Columns.Add(new DataColumn("IsExistDwfDwg",typeof(bool)));
dr = tb.NewRow();
dr[0]=strFileName;
dr[1]=intdownid;
dr[2]="文件";
dr[3]="["+base.Visitor.UserName+"]"+base.Visitor.UserAccount;
dr[4]=false;
tb.Rows.Add(dr);
lyb_abiandbel 2005-09-19
  • 打赏
  • 举报
回复
可能你的sg根本没有建立对象!
silentwins 2005-09-18
  • 打赏
  • 举报
回复
sg是什么?声明了么?
Label1没有声明就用也会出错
还有,最重要,确保sg已经绑定了数据(即使数据是空值也要绑)!
jerrie_1 2005-09-18
  • 打赏
  • 举报
回复
大家来帮帮忙啦

110,526

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧