当前,我正在尝试在网页上显示电子邮件列表,并且正在使用Treeview显示电子邮件文件夹,并使用GridView在电子邮件文件夹中显示内容,并且在Gridview上有分页功能,应该允许浏览带有以下内容的电子邮件列表在相应的电子邮件文件夹中。
但是,在页面初始加载时,我无法选择页面索引来获取NullReferenceException。我正在使用TV_EmaiBox检索选定的节点并将文件夹值传递到GetListEmailList方法中以检索电子邮件。
protected void GV_EmailList_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
GV_EmailList.PageIndex = e.NewPageIndex;
string checkFolder = TV_EmaiBox.SelectedNode.Value.ToString();
this.GetListEmailList(checkFolder);
}
catch (Exception ex)
{
LB_ActionError.Text = ex.StackTrace.ToString();
}
}
我的GridView代码
<asp:GridView ID="GV_EmailList" runat="server" BorderWidth="1px" BorderColor="#CCCCCC"
CellPadding="2" AutoGenerateColumns="False" HorizontalAlign="Left" Visible="False" BorderStyle="Solid" AllowPaging="True" OnPageIndexChanging="GV_EmailList_PageIndexChanging" OnSelectedIndexChanged="GV_EmailList_SelectedIndexChanged" PageSize="5" Width="100%">
<RowStyle BackColor="White" HorizontalAlign="Left" VerticalAlign="Top" />
我的TreeView代码
<asp:TreeView ID="TV_EmaiBox" runat="server" NodeWrap="True" ShowLines="True" ImageSet="XPFileExplorer"
ExpandDepth="1" OnSelectedNodeChanged="TV_EmaiBox_SelectedNodeChanged">
<RootNodeStyle Font-Bold="True" ForeColor="Black" />
<LeafNodeStyle Font-Italic="True" ForeColor="Blue" />
</asp:TreeView>
我只想知道如何在GridView页面索引更改中传递TreeNode值。假设我的TreeNode当前值为Inbox,因此OnPageIndexChanging它应显示该文件夹中的电子邮件列表。
GetListEmailList方法
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);
}
}
我的页面加载方法
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);
}
TresView SelectedNodeChange方法
protected void TV_EmaiBox_SelectedNodeChanged(object sender, EventArgs e)
{
string checkFolder = TV_EmaiBox.SelectedNode.Value.ToString();
this.GetListEmailList(checkFolder);
}