Abbas Abbas - 4 years ago 171
ASP.NET (C#) Question

How to select the particular list box item using Jquery?

I want to select one of the list box item when user select the table row.
This is my output aspx.page


The last item user added
SupplierCode
to a table by clicking
ADD Button
. When user want to modify the records from table, once they click that particular row, the value should move to FilterValue and Field in the list box should select that particular Field Name which is selected by user.

Now user select the first row to modify the value. That value is moved to
FilterValue textbox
, But list box item is not selected automatically to
StoreID



see this pic

But when i check the code in browser. it shows selected for that particular item which item user wants to select. But the color is not changed.

This is my code

Jquery code

//SELECT Table ROW
$(document).on("click", '#queryTable tbody tr', function () {
var tr = $(this);
var FieldName = tr.find("td:first").text();
var Values = tr.find("td:last").text();

FieldName = FieldName.replace('AND ', '');
FieldName = FieldName.replace('OR ', '');

Values = Values.replace('IN(', '');
Values = Values.replace(')', '');
alert(FieldName + ' ' + Values);

$("#FilterField option[value=" + FieldName + "]").attr("selected", true);
$("#txtFilterValue").val(Values);
});

K D K D
Answer Source

try with following code and check if it works

 //SELECT Table ROW
$(document).on("click", '#queryTable tbody tr', function () {
    var tr = $(this);
    var FieldName = tr.find("td:first").text();
    var Values = tr.find("td:last").text();

    FieldName = FieldName.replace('AND ', '');
    FieldName = FieldName.replace('OR ', '');

    Values = Values.replace('IN(', '');
    Values = Values.replace(')', '');
    //alert(FieldName + ' ' + Values); provided your FieldName as correct value

    $("#FilterField").val(FieldName);
    $("#txtFilterValue").val(Values);
});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download