Posted
on Apr 10, 2011
(permalink)
Hello everybody, first I apologize, I'm using a translator because my English is terrible.
I have an application which I have a RadTreeView inside a RadComboBox, but trying to save the database he is saving the text and not the select value.
How could I solve this problem? I believe it is a small detail.
JavaScript:
<script type="text/javascript">
function ApplicationNodeClicking(sender, args) {
var comboBox = $find("<%= RadComboBoxApplications.ClientID %>");
var node = args.get_node()
comboBox.set_text(node.get_text());
//comboBox.set_value(node.get_value());
comboBox.trackChanges();
comboBox.get_items().getItem(0).set_value(node.get_text());
comboBox.commitChanges();
comboBox.hideDropDown();
}
function StopPropagation(e) {
if (!e) {
e = window.event;
}
e.cancelBubble = true;
}
function OnClientDropDownOpenedHandler(sender, eventArgs) {
// var tree = sender.get_items().getItem(0).findControl("RadTreeViewApplications");
// var selectedNode = tree.get_selectedNode();
// if (selectedNode)
// {
// selectedNode.scrollIntoView();
// }
}
</script>
<telerik:RadComboBox ID="RadComboBoxApplications" runat="server"
ShowToggleImage="True" Style="vertical-align: middle;"
OnClientDropDownOpened="OnClientDropDownOpenedHandler"
EmptyMessage="Selecione uma categoria"
Width="300px"
oninit="RadComboBoxApplications_OnInit">
<ItemTemplate>
<div id="div1">
<telerik:RadTreeView ID="RadTreeViewApplications" ShowLineImages="true" runat="server"
OnClientNodeClicking="ApplicationNodeClicking">
</telerik:RadTreeView>
</div>
</ItemTemplate>
<Items>
<telerik:RadComboBoxItem Text="" />
</Items>
</telerik:RadComboBox>
<script type="text/javascript">
var div1 = document.getElementById("div1");
div1.onclick = StopPropagation;
</script>
aspx.cs
private void bindApplicationsTree(ref RadTreeView objtree)
{
SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand sqlCommand = new SqlCommand("select * from ArticleCategory", sqlConnection);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
sqlConnection.Open();
DataSet dsApplications = new DataSet();
sqlDataAdapter.Fill(dsApplications);
sqlConnection.Close();
sqlDataAdapter.Dispose();
objtree.DataValueField = "CategoryId";
objtree.DataTextField = "Text";
objtree.DataFieldParentID = "ParentId";
objtree.DataFieldID = "CategoryId";
objtree.DataSource = dsApplications;
objtree.DataBind();
}
protected void RadComboBoxApplications_OnInit(object sender, EventArgs e)
{
RadComboBox objCombo = ((RadComboBox)sender);
RadTreeView objTree = (RadTreeView)objCombo.Items[0].FindControl("RadTreeViewApplications");
if (null != objTree)
bindApplicationsTree(ref objTree);
else
{
Response.Write("<p>Warning: Unable to find the tree</p>");
}
}
When I save the database, I get the error:
Conversion failed when converting the nvarchar value 'E-mail' to data type int.
That is, RadComboBox is falling in the text, not the DataValueField
Can you help me how to solve this problem?Thanks