REad dataset of a drop down list

pamela rizk
pamela rizk used Ask the Experts™
on
hi

i have a drop down list filled from server side as below:
(where SelectStatusCbo is the drop down and lStatusDS is the dataset)
 With SelectStatusCbo
                            .DataSource = lStatusDS.Tables(0)
                            .DataTextField = "Status_DescE" '"P_cle_stat"
                            .DataValueField = "internalCode" '"p_stat_int"
                            .DataBind()
                        End With
the dataset contains teh below column :
Process1, Status_DescE and internalCode
nowin javascript i need to do  the below:
 $("#" + SelectStatusCbo.id).on("change", function () {
//need to read the dataset and appropriate column of teh datase how to dow it?
}
well i need to read the dataset of the drop down in javascript goto the selected index and read each column value how to do it?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
leakim971Multitechnician
Top Expert 2014

Commented:
what about replacing :
.DataValueField = "internalCode"
by :
.DataValueField = "internalCode" +  "|" + Process1

and use :
$("#" + SelectStatusCbo.id).on("change", function () {
 var arrPipe = $(this).val().split("|");
 var internalCode = arrPipe[0];
 var Process1 = arrPipe[1];
 var Status_DescE = $("option:selected", this).text();
});

Open in new window

pamela rizkDeveloper

Author

Commented:
no this solution does not work for me because this user control is used in many other web forms so i cannot change the value field and split the result
 i want a way where i need to  read the dataset  of this drop down from javascript without changing the datavaluefield
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
It is not clear which part you need assistance with
 $("#" + SelectStatusCbo.id).on("change", function () {
//need to read the dataset and appropriate column of teh datase how to dow it?
}

Open in new window

Are you asking how to go back to the server at this point or do you already have the data locally?

What is going to happen in the change handler - what is it the code is meant to do?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Multitechnician
Top Expert 2014
Commented:
so loop over all items of the dropdownlist to add an new attribute, for example "data-process1" for your column Process1
            for(int i=0;i<SelectStatusCbo.Items.length;i++)
            {
                ListItem li = SelectStatusCbo.Items(i);
                DataRow dr = lStatusDS.Tables(0).Rows(i);
                li.Attributes("data-process1", dr("Process1"));
            }

Open in new window


and use :
$("#" + SelectStatusCbo.id).on("change", function () {
 var internalCode = $(this).val();
 var Process1 = $("option:selected", this).data("process1"); // https://api.jquery.com/data/
 var Status_DescE = $("option:selected", this).text();
});

Open in new window


https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset

if that doesn't work, do a right click on your dropdownlost, choose Inspect element, right click on the HTML element and copy the OuterHTML to post it here
pamela rizkDeveloper

Author

Commented:
thank you
leakim971Multitechnician
Top Expert 2014

Commented:
You welcome!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial