目前,我的网页上有一个树形视图和一个网格视图。 TreeView显示“电子邮件收件箱文件夹”列表。 GridView显示来自那些“收件箱”文件夹的电子邮件。但是,当我最初加载我的电子邮件网页时,我的gridView上的分页不起作用并返回错误。我的想法是,我在!IsPostBack方法期间未绑定gridView。但是我正在尝试多种方法来解决此问题。请帮助我调查此问题,并提出解决此问题的最佳方法。请参考以下代码。谢谢
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);
}
}
protected void TV_EmaiBox_SelectedNodeChanged(object sender, EventArgs e)
{
string checkFolder = TV_EmaiBox.SelectedNode.Value.ToString();
this.GetListEmailList(checkFolder);
}
protected void GV_EmailList_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GV_EmailList.PageIndex = e.NewPageIndex;
string checkFolder = TV_EmaiBox.SelectedNode.Value.ToString();
this.GetListEmailList(checkFolder);
}
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);
}
当我单击gridview中的页面索引时,错误来自此行。
string checkFolder = TV_EmaiBox.SelectedNode.Value.ToString();
我知道我正在尝试在GridView方法中调用TreeView对象。有什么办法可以解决此问题?谢谢