This is my add form:
<AddForm>
<ScriptBlock BlockType="HeadScript" RegisterOnce="True" ScriptId="XMODPro_Admin">
<link rel="stylesheet" type="text/css" href="/DesktopModules/XModPro/styles/rcde-admin/styles.css" />
</ScriptBlock>
<SubmitCommand CommandText="INSERT INTO [RCDEProduct_Categry] (ProductId,CategoryId) VALUES(1,1)" />
<ControlDataSource Id="CategoriesDataSource"
CommandText="
SELECT
CONVERT(VARCHAR,ISNULL(ParentCategoryId,-1))+'|'+CONVERT(VARCHAR,Id) AS [Id]
,'['+ CONVERT(VARCHAR,[CategoryNumber]) + '] '+[Name] AS [Name]
FROM
[RCDECategory]
WHERE
ParentCategoryId IS NOT NULL
ORDER BY
ParentCategoryId,
[Name] ASC"
/>
<ControlDataSource Id="RootCategoriesDataSource"
CommandText="
SELECT
[Id]
,'['+ CONVERT(VARCHAR,[CategoryNumber]) + '] '+[Name] AS [Name]
FROM
[RCDECategory]
WHERE
ParentCategoryId IS NULL
ORDER BY
[Name] ASC"
/>
<div>
<div>
<h3>New Category Assignment for: [[Form:Id]]</h3>
</div>
<div>
<ListBox id="CategoriesListBox" cssclass="collapse"
DataSourceID="CategoriesDataSource" DataTextField="Name" DataValueField="Id" />
<ValidationSummary CssClass="alert alert-danger" Id="ValidationSummary" DisplayMode="List" HeaderText="Please check your entries:"></ValidationSummary>
<div>
<Label For="Category">Category</Label>
<DropDownList id="Category" cssclass="form-control"
DataSourceId="RootCategoriesDataSource" DataValueField="Id" DataTextField="Name" DataType="int32"
Nullable="False" />
<Validate Target="Category" cssclass="text-danger"
Type="required" Text="- Must select a Category." Message="- Must select a Category." />
</div>
<div>
<Label For="Subcategory">Subcategory</Label>
<DropDownList id="Subcategory" cssclass="form-control"
DataType="int32" Nullable="True" />
</div>
</div>
<div>
<AddButton Text="Add" cssclass="btn btn-primary"></AddButton>
<CancelButton Text="Cancel" cssclass="btn btn-default" Visible="true"></CancelButton>
</div>
</div>
<jQueryReady>
//+- Initialize Variabes
var $rootCategories = $('[name$="CategoriesListBox"]');
//+- Define Event Handlers
$('body')
.on('change','select[name$="Category"]',CategoryChange);
//+- Trigger Evens
$('select[name$="Category"]').change();
//+- Event Handlers
function CategoryChange(){
var selectedCategory = $(this).val();
var $options = $rootCategories.find('option[value^="' + selectedCategory + '|"]').clone();
$options.each(function(){
var val = $(this).val();
var categoryId = val.split("|")[1];
$(this).val(categoryId);
});
$('[name$="Subcategory"] option').remove();
$('[name$="Subcategory"]').append($options);
$('[name$="Subcategory"]').closest('.form-group').show();
if($('[name$="Subcategory"] option').length==0){
$('[name$="Subcategory"]').closest('.form-group').hide();
}
}
</jQueryReady>
</AddForm>