初始页面加载时出现Gridview错误 [英] Gridview error on initial pageload

查看:67
本文介绍了初始页面加载时出现Gridview错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



目前我的网页显示gridview中的电子邮件列表和来自treeview的电子邮件文件夹。但是,如果我在初始页面加载/首次加载时更改页面索引,则会给出错误。



但如果我点击任何TreeView,然后点击Gridview分页。它不会返回任何错误。



Hi Everyone,

Currently my webpage displays list of emails in gridview and emails folders from treeview. However, if I change page index on Initial Page Load/First Time Load it gives me error.

But If i click on any of the TreeView and then click on Gridview pagination. It does not return any error.

<pre>protected void Page_Load(object sender, EventArgs e)
        {
            B_EmailMsgDelete.Attributes.Add("onclick", 
        "javascript:if(!doDeleteEmailMsg()) return false;");
            IB_EmailMover.Attributes.Add("onclick", "javascript:if(!doMoveEmailMsg()) return false;");
            
            if (!IsPostBack)
            {
                TreeNode rootTreeNode = new TreeNode();
                rootTreeNode.Text = string.Format(CultureInfo.CurrentCulture, " {0}", this.curEmailBox);
                rootTreeNode.Value = this.EmailFolderList[0];
                rootTreeNode.ImageUrl = "../../Images/emailbox.gif";

                for (int i = 0; i < this.EmailFolderList.Length; i++)
                {
                    if (i > 0)
                    {
                        TreeNode treeNode = new TreeNode();
                        treeNode.Text = string.Format(CultureInfo.CurrentCulture, " {0}", this.EmailFolderList[i]);
                        treeNode.Value = this.EmailFolderList[i];
                        treeNode.ImageUrl = "../../Images/folder.gif";
                        rootTreeNode.ChildNodes.Add(treeNode);
                    }

                    DL_MoveTo.Items.Add(this.EmailFolderList[i]);
                }

                TV_EmaiBox.Nodes.Add(rootTreeNode);
                this.GetListEmailList(rootTreeNode.Value);
            }
        }





TreeView On Page更改索引



TreeView On Page Change Index

protected void TV_EmaiBox_SelectedNodeChanged(object sender, EventArgs e)
        {
            string checkFolder = TV_EmaiBox.SelectedNode.Value.ToString();
            this.GetListEmailList(checkFolder);
        }





GridList On Page Index



GridList On Page Index

protected void GV_EmailList_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GV_EmailList.PageIndex = e.NewPageIndex;
    string checkFolder = TV_EmaiBox.SelectedNode.Value.ToString();
    this.GetListEmailList(checkFolder);
}





GetEmailList方法



GetEmailList Method

private void GetListEmailList(string folderName)
       {
           try
           {
               LB_ActionError.Text = string.Empty;
               PH_MsgDetail.Visible = true;

               var emails = EmailMsg.GetEmailListInFolder(folderName);
               LB_CurBox.Text = string.Format(CultureInfo.CurrentCulture, "{0} ({1})", folderName, emails.Count);

               int intTotal = emails.Count;
               if (intTotal == 0)
               {
                   LB_ActionStatus.Text = Utility.SetActStatus(true, "There is no email message found in this folder.");
                   GV_EmailList.DataSource = new ArrayList();
                   GV_EmailList.DataBind();
                   GV_EmailList.Visible = false;
               }
               else
               {
                   LB_ActionStatus.Text = Utility.SetActStatus(true, string.Format(CultureInfo.CurrentCulture, "There are {0} email message(s) found in this folder.", intTotal));
                   GV_EmailList.DataSource = emails;
                   GV_EmailList.DataBind();
                   GV_EmailList.Visible = true;

                   GV_EmailList.SelectedIndex = -1;
               }
           }
           catch (Exception ex)
           {
               LB_ActionStatus.Text = Utility.SetActStatus(false, ex.Message.ToString());
           }

           LB_AdminEmailBox.Text = string.Format(CultureInfo.CurrentCulture, Entity.GetSetting("MailBoxAddress"), folderName);
       }
   }





我尝试了什么: < br $> b $ b



What I have tried:

I have tried many approaches but no luck so far. What I want is when this page is loaded for the first time. GridView page index should not return any when I change page index. 

推荐答案

当你想它们时,事件并不总是会发生。当火灾发生时你不能认为事物处于有效状态。 (特别是在启动期间)



您不能假设选定项目(节点)有效,除非您首先检查空值,例如。



Events do not always fire when you "think" they will. You cannot assume things are in a valid state when they do fire. (particularly during "start up")

You cannot assume a "selected item" (node) is valid unless you check for null first, for example.

string checkFolder = TV_EmaiBox.SelectedNode.Value.ToString();


这篇关于初始页面加载时出现Gridview错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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