关于DataView的一个问题.....郁闷中 " DataView dv = new DataView(ds.Tables[0]);"最好这样写,应该写成: DataView dv= ds.Table[0].DefalutView; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 dataset和dataview不要放在viewstate里,这样viewstate会过大可以放在Session里,这样放在服务器端较好(虽然也占服务器资源)另外,你id全设置成0001做什么? TO:Simplare(简单) ID设置只是发贴的时候说说而已..程序本身是接受变量的。是不同的。....我现在想怎么才能实现我要的功能.有没有别的好方法.放在Session里面该怎么样写 ft,写错了!ds.Table[0].DefalutView;应该是.DefaultView 你可以把DataView dv 声明成全局static变量然后就可以在此访问它了。也不用什么session了 private void CreateDataSet() { DataSet ds=(DataSet) this.ViewState["ds"]; DataView dvTree = ds.Tables[0].DefaultView ; //过滤ParentID,得到当前的所有子节点 //dvTree.RowFilter = "[SendPID] = " + ParentID; dvTree.AllowEdit=true; foreach(DataRowView Row in dvTree) { string content = ""; content = Row["idx"].ToString() Row["txtcontent"] = content; Row.EndEdit(); } this.ViewState["dv"]=dvTree; }private void AddTree(string ParentID,TreeNode pNode){//DataSet ds=(DataSet) this.ViewState["ds"]; //DataView dvTree = new DataView(ds.Tables[0]);//过滤ParentID,得到当前的所有子节点DataView dvTree=(DataView)this.ViewState["dv"];dvTree.RowFilter = "[SendPID] = " + ParentID; foreach(DataRowView Row in dvTree) { TreeNode Node=new TreeNode() ; if(pNode == null) { //添加根节点 Node.Text = Row["txtcontent"].ToString(); j_TreeView.Nodes.Add(Node); Node.Expanded=true; AddTree(Row["acceptpid"].ToString(), Node); //再次递归 } else { //?添加当前节点的子节点 Node.Text = Row["txtcontent"].ToString(); pNode.Nodes.Add(Node); Node.Expanded = true; AddTree(Row["acceptpid"].ToString(),Node); //再次递归 } } }这就是大概的程序...请各位看看那里有问题.现在总报1行不存在. 把ds放在Session中,我以前也遇到过类似问题. 在位置 1 处没有任何行。 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IndexOutOfRangeException: 在位置 1 处没有任何行。源错误: 行 166: else 行 167: { //?添加当前节点的子节点行 168: Node.Text = Row["txtcontent"].ToString();行 169: pNode.Nodes.Add(Node);行 170: Node.Expanded = true; 源文件: c:\inetpub\wwwroot\police\j_track_show.aspx.cs 行: 168 堆栈跟踪: [IndexOutOfRangeException: 在位置 1 处没有任何行。] System.Data.DataView.GetRecord(Int32 recordIndex) System.Data.DataView.IsOriginalVersion(Int32 index) System.Data.DataRowView.get_Item(String property) police.j_show_track.AddTree(String ParentID, TreeNode pNode) in c:\inetpub\wwwroot\police\j_track_show.aspx.cs:168 police.j_show_track.AddTree(String ParentID, TreeNode pNode) in c:\inetpub\wwwroot\police\j_track_show.aspx.cs:164 police.j_show_track.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\police\j_track_show.aspx.cs:41 System.Web.UI.Control.OnLoad(EventArgs e) System.Web.UI.Control.LoadRecursive() System.Web.UI.Page.ProcessRequestMain() 停在 Node.Text = Row["txtcontent"].ToString(); 这说明Row[]中没有txtcontent的索引需要调试一下在出现错误的一行添加断点然后添加Row的监视,看看Row里面是否有值,然后查看每个值相对索引是什么 我发现在了问题所在了...当执行再次递归的时候dvTree.RowFilter = "[SendPID] = " + ParentID; 如果没有数据,执行后dvTree.count=0 这样的话foreach循环以后并不是再执行一次dvTree.RowFilter = "[SendPID] = " + ParentID 程序只在foreach里面执行.dvtree里面还是没有数据...这个问题该怎么解决呢 怎么获取qq空间 最近访问人列表 急需一个方法??? 20分! .孟子,思归...帮帮我.困扰了我一天的问题....关于.net调用delphi写的dll.在线等.解决立即给分 问一个关于Bolg显示方式的讨论:如何快速显示Blog内容 5位或6位由数字和字母组成的字符串的正则表达式 如何規範DateTime的格式 最简单的数据库连接问题 出毛病了 讨论:论坛这样的程序,用户在线记录应该放哪里好? 谁知道哪儿有学生就业管理系统!!!! 怎样向表中添加一条记录??? 用户控件为什么不能正常运行?总是提示下载。 我在VS.NET上通过修改项目配置信息打开别人的项目出现的问题。
ID设置只是发贴的时候说说而已..程序本身是接受变量的。是不同的。....我现在想怎么才能实现我要的功能.有没有别的好方法.放在Session里面该怎么样写
ds.Table[0].DefalutView;应该是.DefaultView
然后就可以在此访问它了。
也不用什么session了
{
DataSet ds=(DataSet) this.ViewState["ds"];
DataView dvTree = ds.Tables[0].DefaultView ;
//过滤ParentID,得到当前的所有子节点
//dvTree.RowFilter = "[SendPID] = " + ParentID;
dvTree.AllowEdit=true;
foreach(DataRowView Row in dvTree)
{
string content = "";
content = Row["idx"].ToString()
Row["txtcontent"] = content;
Row.EndEdit();
}
this.ViewState["dv"]=dvTree;
}private void AddTree(string ParentID,TreeNode pNode)
{
//DataSet ds=(DataSet) this.ViewState["ds"];
//DataView dvTree = new DataView(ds.Tables[0]);
//过滤ParentID,得到当前的所有子节点
DataView dvTree=(DataView)this.ViewState["dv"];
dvTree.RowFilter = "[SendPID] = " + ParentID;
foreach(DataRowView Row in dvTree)
{
TreeNode Node=new TreeNode() ;
if(pNode == null)
{ //添加根节点
Node.Text = Row["txtcontent"].ToString();
j_TreeView.Nodes.Add(Node);
Node.Expanded=true;
AddTree(Row["acceptpid"].ToString(), Node); //再次递归
}
else
{ //?添加当前节点的子节点
Node.Text = Row["txtcontent"].ToString();
pNode.Nodes.Add(Node);
Node.Expanded = true;
AddTree(Row["acceptpid"].ToString(),Node); //再次递归
}
}
}
这就是大概的程序...请各位看看那里有问题.现在总报1行不存在.
我以前也遇到过类似问题.
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IndexOutOfRangeException: 在位置 1 处没有任何行。源错误:
行 166: else
行 167: { //?添加当前节点的子节点
行 168: Node.Text = Row["txtcontent"].ToString();
行 169: pNode.Nodes.Add(Node);
行 170: Node.Expanded = true;
源文件: c:\inetpub\wwwroot\police\j_track_show.aspx.cs 行: 168 堆栈跟踪:
[IndexOutOfRangeException: 在位置 1 处没有任何行。]
System.Data.DataView.GetRecord(Int32 recordIndex)
System.Data.DataView.IsOriginalVersion(Int32 index)
System.Data.DataRowView.get_Item(String property)
police.j_show_track.AddTree(String ParentID, TreeNode pNode) in c:\inetpub\wwwroot\police\j_track_show.aspx.cs:168
police.j_show_track.AddTree(String ParentID, TreeNode pNode) in c:\inetpub\wwwroot\police\j_track_show.aspx.cs:164
police.j_show_track.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\police\j_track_show.aspx.cs:41
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
需要调试一下
在出现错误的一行添加断点
然后添加Row的监视,看看Row里面是否有值,然后查看每个值相对索引是什么