TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
LI CHOO
NA
19
590
How to remain the treeview after redirect to another page?
Apr 2 2021 1:31 AM
Im currently using this method to bind my treeview, After i expand the treeview and click the node, it will redirect to another page, and then the treeview will be refresh to default, which means showing the treeview before expanding.. so i need to save the treeview state in order to remain the treeview state. i had tried the below method but it's not working, anyone can help..
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!Page.IsPostBack)
{
if
(Session[
"ExpandedNodes"
] !=
null
)
{
((List<
string
>)Session[
"ExpandedNodes"
]).ForEach(a => TreeView1.FindNode(a).Expanded =
true
);
}
LoadTransactionMenu();
}
}
private
void
LoadTransactionMenu()
{
//TRANSACTION MENU // this is used to bind the data to the treeview
string
SubModuleID, SubModuleNM, DocModuleID, DocModuleName, MenuTransID, MenuTransName;
SqlConnection con =
new
SqlConnection(ConString);
string
CmdString =
"SELECT SUBMODULEID, SUBMODULENM, URLNAME FROM SUBMODULE"
;
SqlCommand cmd =
new
SqlCommand(CmdString, con);
SqlDataAdapter sda =
new
SqlDataAdapter(cmd);
DataTable dt =
new
DataTable();
sda.Fill(dt);
TreeNode node1 =
new
TreeNode();
node1.Text =
"TRANSACTION MENU"
;
TreeView1.Nodes.Add(node1);
for
(
int
i = 0; i < dt.Rows.Count; i++)
{
SubModuleID = dt.Rows[i][
"SUBMODULEID"
].ToString();
SubModuleNM = dt.Rows[i][
"SUBMODULENM"
].ToString();
TreeNode SubModuleNode =
new
TreeNode(SubModuleNM, SubModuleID);
SubModuleNode.NavigateUrl = dt.Rows[i][
"URLNAME"
].ToString();
node1.ChildNodes.Add(SubModuleNode);
CmdString =
"SELECT DDID, DOCNAME, DDADDRESS FROM DOCMODULE WHERE SUBMODULEID=@SUBMODULEID"
;
cmd =
new
SqlCommand(CmdString, con);
cmd.Parameters.AddWithValue(
"@SUBMODULEID"
, SubModuleID);
sda =
new
SqlDataAdapter(cmd);
DataTable dt2 =
new
DataTable();
sda.Fill(dt2);
for
(
int
j = 0; j < dt2.Rows.Count; j++)
{
DocModuleID = dt2.Rows[j][
"DDID"
].ToString();
DocModuleName = dt2.Rows[j][
"DOCNAME"
].ToString();
TreeNode DocModuleNode =
new
TreeNode(DocModuleName, DocModuleID);
DocModuleNode.NavigateUrl = dt2.Rows[j][
"DDADDRESS"
].ToString();
SubModuleNode.ChildNodes.Add(DocModuleNode);
CmdString =
"SELECT DID, DNAME, DADDRESS FROM MENUTRANSACTION WHERE DDID=@DDID AND UID= '"
+ Session[
"UserID"
] +
"'"
;
cmd =
new
SqlCommand(CmdString, con);
cmd.Parameters.AddWithValue(
"@DDID"
, DocModuleID);
sda =
new
SqlDataAdapter(cmd);
DataTable dt3 =
new
DataTable();
sda.Fill(dt3);
for
(
int
k = 0; k < dt3.Rows.Count; k++)
{
MenuTransID = dt3.Rows[k][
"DID"
].ToString();
MenuTransName = dt3.Rows[k][
"DNAME"
].ToString();
TreeNode MenuTransNode =
new
TreeNode(MenuTransName, MenuTransID);
MenuTransNode.NavigateUrl = dt3.Rows[k][
"DADDRESS"
].ToString();
DocModuleNode.ChildNodes.Add(MenuTransNode);
}
if
(DocModuleNode.ChildNodes.Count == 0)
{
SubModuleNode.ChildNodes.Remove(DocModuleNode);
}
}
if
(SubModuleNode.ChildNodes.Count == 0)
{
node1.ChildNodes.Remove(SubModuleNode);
}
}
}
protected
void
TreeView1_SelectedNodeChanged(
object
sender, EventArgs e)
{
List<
string
> expandedNodes =
new
List<
string
>();
//get all expanded nodes
TreeView1.Nodes.Cast<TreeNode>().ToList().ForEach(a => GetExpandedStatus(a, expandedNodes));
//collapse all to reset the treeview
TreeView1.CollapseAll();
//save expanded node value paths
Session[
"ExpandedNodes"
] = expandedNodes;
}
public
void
GetExpandedStatus(TreeNode node, List<
string
> ExpandedNodes)
{
//check if node is expanded
if
(node.Expanded.GetValueOrDefault(
false
))
ExpandedNodes.Add(node.ValuePath);
node.ChildNodes.Cast<TreeNode>().ToList().ForEach(a => GetExpandedStatus(a, ExpandedNodes));
}
Reply
Answers (
0
)
.net mvc form-data api call
CRUD using ASP.NET MVC