Visual Studio 2008
.Net 3.5 SP1
Ajax controls (Q3 2010)
I always get count 0 when trying to get the checkedNodes from the treeview, i need to get the value of the node (can only be one checked node that is controlled by a javascript) and when i finally do a postback i want to get the value and do an insert into a database, cant really se the problem, is there any event that i have set wrong? seems that the client dousent set the node to checked or the server cant seem to find the checked node some how.
On page load i bind the treeview from a seperate method,
The bind method
Treeviewbuilder method thats used above, to build the tree
button, postback to make insert, cant get values (always count 0)
Treeview inside combobox (ASPX)
Javascript, OnClientNodeChecked from treeview above
Javascript event from validator in aspx above
.Net 3.5 SP1
Ajax controls (Q3 2010)
I always get count 0 when trying to get the checkedNodes from the treeview, i need to get the value of the node (can only be one checked node that is controlled by a javascript) and when i finally do a postback i want to get the value and do an insert into a database, cant really se the problem, is there any event that i have set wrong? seems that the client dousent set the node to checked or the server cant seem to find the checked node some how.
On page load i bind the treeview from a seperate method,
protected
void
Page_Load(
object
sender, EventArgs e)
{
UI ui = GetUI();
//if (!IsPostBack)
//{
// BindTvCaseType(ui);
//}
if
(Session[Common.userSession] ==
null
|| ((AdManager.UserInfo)Session[Common.userSession]).Status == AdManager.LoginStatus.Error)
Response.Redirect(
"default.aspx"
);
//UI ui = GetUI();
BindCmbSeverity(ui);
BindCmbCharacter(ui);
BindTvCaseType(ui);
BindTvCaseType(ui);
//This is where i bind the treeview
ui.tvType.ID =
"tvCaseType"
;
ui.labEmail.Text = (((AdManager.UserInfo)Session[Common.userSession]).Email);
if
((((AdManager.UserInfo)Session[Common.userSession]).Email) ==
""
)
{
ui.panEmailNotification.Visible =
false
;
}
ui.btnStep2.Attributes.Add(
"OnClick"
,
"checkStep1(); return false;"
);
ui.btnStep3.Attributes.Add(
"OnClick"
,
"checkStep2(); return false;"
);
}
The bind method
private
void
BindTvCaseType(UI ui)
{
ui.tvType.Nodes.Clear();
dsHelpdeskG2TableAdapters.typesTableAdapter taCaseTypes =
new
dsHelpdeskG2TableAdapters.typesTableAdapter();
dsHelpdeskG2.typesDataTable dtCaseTypes = taCaseTypes.GetData();
ui.tvType.Nodes.AddRange(TreeviewBuilder.BuildRecursive(
null
, 0,
null
, dtCaseTypes,
null
));
}
Treeviewbuilder method thats used above, to build the tree
public
static
List<RadTreeNode> BuildRecursive(dsHelpdeskG2.typesRow drNodeRow,
int
rowLevel, dsHelpdeskG2.permissionsDataTable dtPermissions, dsHelpdeskG2.typesDataTable dtTypes,
AdManager.UserInfo us)
{
List<RadTreeNode> nodeList =
new
List<RadTreeNode>();
if
(rowLevel > 5)
return
nodeList;
int
c_ty_id = 0;
if
(drNodeRow !=
null
)
c_ty_id = drNodeRow.ty_id;
var nodeTable = from c
in
dtTypes
where c.ty_parent_id == c_ty_id
orderby c.ty_id
select c;
foreach
(var nodeRow
in
nodeTable)
{
RadTreeNode node =
new
RadTreeNode();
node.Value = nodeRow.ty_id.ToString();
node.Text = nodeRow.ty_name;
node.Nodes.AddRange(BuildRecursive(nodeRow, rowLevel + 1, dtPermissions, dtTypes, us));
//node.ID = "tvTypeNode" + nodeRow.ty_id;
if
(node.Nodes.Count > 0)
{
//om den inte har childs
node.Checkable =
false
;
}
else
{
//har childs..
//node.ch
}
nodeList.Add(node);
}
return
nodeList;
}
button, postback to make insert, cant get values (always count 0)
protected
void
btnSendCase_Click(
object
sender, EventArgs e)
{
UI ui = GetUI();
dsHelpdeskG2TableAdapters.casesTableAdapter dtaCases =
new
dsHelpdeskG2TableAdapters.casesTableAdapter();
double
anstId = ((AdManager.UserInfo)Session[Common.userSession]).AnstId;
var temp = Request.Params;
int
caseTypeId =
int
.Parse(ui.tvType.CheckedNodes[0].Value);
//This is where i set a int value and trye to retreave the checked node.
int
caseSeverity =
int
.Parse(ui.cmbSeverity.SelectedValue);
int
caseCharacter =
int
.Parse(ui.cmbCharacter.SelectedValue);
string
userIP = Request.ServerVariables[
"REMOTE_ADDR"
];
string
userHostname = Request.ServerVariables[
"REMOTE_HOST"
];
string
caseHeader = ui.txtRubrik.Text;
bool
caseNotification;
if
(ui.rbEmailYes.Checked)
caseNotification =
true
;
else
caseNotification =
false
;
dtaCases.Insert(anstId,
null
, caseTypeId, caseSeverity, caseCharacter, DateTime.Now, userIP,
null
, caseHeader, 1, caseNotification,
null
,
null
, userHostname);
}
Treeview inside combobox (ASPX)
<
telerik:RadComboBox
ID
=
"cmbCaseType"
runat
=
"server"
Skin
=
"Windows7"
Height
=
"160px"
Style
=
"vertical-align: middle;"
Width
=
"225px"
>
<
ItemTemplate
>
<
div
id
=
"div1"
>
<
telerik:RadTreeView
ID
=
"tvCaseType"
runat
=
"server"
CheckBoxes
=
"True"
Height
=
"160px"
Width
=
"100%"
OnClientNodeChecked
=
"nodeClicking"
>
</
telerik:RadTreeView
>
</
div
>
</
ItemTemplate
>
<
Items
>
<
telerik:RadComboBoxItem
Text
=
""
/>
</
Items
>
<
CollapseAnimation
Type
=
"None"
/><
ExpandAnimation
Type
=
"None"
/>
</
telerik:RadComboBox
><
br
/>
<
asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="checkTypeTreeview" ErrorMessage="CustomValidator" Display="Dynamic" ValidationGroup="Step1">Vnligen ange En rendetyp</asp:CustomValidator
>
<br
/>
Javascript, OnClientNodeChecked from treeview above
var
oldNode;
function
nodeClicking(sender, args)
{
var
comboBox = $find(
"ctl00_phContent_pbCaseRegistration_i0_i0_cmbCaseType"
);
var
node = args.get_node()
if
(oldNode !=
null
)
{
oldNode.set_checked(
false
);
}
node.set_checked(
true
);
oldNode = node;
comboBox.set_text(node.get_text());
comboBox.trackChanges();
comboBox.get_items().getItem(0).set_text(node.get_text());
comboBox.commitChanges();
comboBox.hideDropDown();
}
Javascript event from validator in aspx above
function
checkTypeTreeview(source, arguments)
{
var
treeView = document.getElementById(
"ctl00_phContent_pbCaseRegistration_i0_i0_cmbCaseType_i0_tvCaseType"
);
var
checkBoxes = treeView.getElementsByTagName(
"input"
);
var
checkedCount = 0;
for
(
var
i = 0; i < checkBoxes.length; i++)
{
if
(checkBoxes[i].checked)
{
checkedCount++;
}
}
if
(checkedCount > 0 && checkedCount < 2)
{
arguments.IsValid =
true
;
}
else
{
arguments.IsValid =
false
;
}
}