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 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
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 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);
}
}
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.