GridView显示有/无数据 [英] GridView Display With / WithOut Data

查看:90
本文介绍了GridView显示有/无数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 GridView ,带有/不带有数据,我也想显示我的"GridView".
为此,我编写了这样的代码,但在下面突出显示的行中显示了错误.

I have a GridView with / without Data also i want to display my ''GridView''.
For that I wrote Code like this but it show the error in below highlighted line.

DataSet dsPAM = objEDMS.Get_Project_Alert_Member(ddlProject.SelectedValue);

                ViewState["PAM"] = dsPAM.Tables[0];

                DataView dvTo = dsPAM.Tables[0].DefaultView;
                dvTo.RowFilter = "Receiver_Type=2";
                if (dvTo.ToTable().Rows.Count != 0)
                {
                    gvTo.DataSource = dvTo;
                    gvTo.DataBind();
                }
                else
                {
                    dvTo.ToTable().Rows.Add(dvTo.ToTable().NewRow());
                    gvTo.DataSource = dvTo.ToTable();
                    gvTo.DataBind();
                    gvTo.Rows[0].Visible = false;
                }



错误消息为:
该行已经属于另一个表.



Error Msg is :
This row already belongs to another table.

推荐答案

您两次调用totable,但您丢弃了第一个实例.上面的行是您的核心问题.抓取返回结果并绑定到该结果.
You''re calling totable twice, but you discard the first instance. The line above is your core issue. Grab that return result and bind to that.



代替这个:
Hi,
Instead of this:
dvTo.ToTable().Rows.Add(dvTo.ToTable().NewRow());


试试这个:


Try this:

dvTo.ToTable().Rows.Add(dvTo.ToTable().NewRow().ItemArray);




--Amit




--Amit


这篇关于GridView显示有/无数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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