Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

i am unable to bind my Javascript to a particular column in my View. It works for the first drop down in the column but fails for the rest. Can you please assist on it.

My View is as follow:

JavaScript
  $(document).ready(function () {

        $("#SourceTable").change(function () {
            $("#ColumnNames").empty();
            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetColumn")',
                dataType: 'json',
                data: { TableName: $("#SourceTable option:selected").text() },
                success: function (str) {
                    $.each(str, function (Value, Text) {
                        //alert(Value + ' ' + Text.Value);
                        $("#ColumnNames").append('<option value ="'+Value+ '">' +
                        Text.Text + '</option>');
                    });
                },
                error: function (ex) {
                    alert('Failed to retrieve columns.' + ex);
                }
            });
            return false;
        })
    });

</script>




@wg.GetHtml(
tableStyle: "gridTable",
headerStyle: "gridHead",
rowStyle: "gridRow",
footerStyle: "gridFooter",
alternatingRowStyle: "gridAltRow",
columns: wg.Columns(
wg.Column("DestnColumn", "Destination Column"),
wg.Column("SourceTable", format: @item => Html.DropDownList("SourceTable", (IEnumerable<SelectListItem>)Model.SourceColumnModel[0].SourceTables,"Select Source")),
wg.Column("ColumnNames", format: @item => @Html.DropDownList("ColumnNames", new SelectList(string.Empty, "Value", "Text"), "Select Column", new { style = "width:200px" })),
// wg.Column(header: "SourceColumn", format: @item1 => Html.DropDownList("value1", (IEnumerable<SelectListItem>)Model.SourceColumnModel[0].SourceColumnsNames)),
wg.Column("DataSize", "Size"),
wg.Column("DataType", "Data Type"))

)
)
Posted
Updated 8-Jan-16 1:38am
Comments
F-ES Sitecore 8-Jan-16 8:49am    
If you have multiple elements in the DOM with the same ID then things like "#yourid" aren't going to work as IDs are supposed to be unique. If that's the case you'll need to use something else to identify your elements like a css class or a "data" attribute.
Sinisa Hajnal 11-Jan-16 2:35am    
Use class or some custom attribute to bind the event. ID should be unique on the page.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900