本文介绍了如何使用datalist viewstate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一些记录的数据表dt3。在其中一个事件中,我提出了两个条件,如果

'furrentable'= null,否则。当我把断点和验证时,它进入'null'区域

,它不应该是dt3有记录。因此,变量'v_MyCart'变为零,这不是我想要发生的。我的要求是,由于dt3有记录,它必须转到'if(dt3.Rows.Count> 0')行。我的方法和代码有任何不妥。我在下面提交我的代码:



I have a datatable dt3 with some records. In one of the event I put 2 conditions, if
'currentable'=null and else. When I put the break point and verified , it enters the 'null' area
which it should not as dt3 has records. Because of this, variable 'v_MyCart' becomes zero which
I dont want to happen. My requirement is, since dt3 has records it has to go to the line 'if(dt3.Rows.Count>0' . Any wrong in my approach and code. I hereunder submit my code:

DataTable dt3 = new DataTable();
                    dt3 = (DataTable)Session["ss"];
                    ViewState["CurrenTable"] = dt3;
                    if (ViewState["CurrentTable"]==null)
                    {
                        v_MyCart = 0;

                    }
                    else
                    {

                        if (dt3.Rows.Count > 0)
                        {

推荐答案

DataTable dt3 = new DataTable();
//First check is your session is null or not
if (Session["ss"] != null)
{
    dt3 = (DataTable)Session["ss"];
    ViewState["CurrenTable"] = dt3; //Now you have assigned a viewstate here
    if (((DataTable)ViewState["CurrentTable"]).Rows.Count == 0)
    { //Check assigned table has any rows or not
        v_MyCart = 0;
    }
    else //if (dt3.Rows.Count > 0)
    {//Data exists do something }
}


这篇关于如何使用datalist viewstate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 10:27