Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Get datasource from dropdownlist with JS

I'm looking for a way to retrieve the datasource of a dropdownlist in c# on the client side using javascript or JQuery. Do you know how to do it?

 <asp:DropDownList id="ddlList" runat="server" width="50%"></asp:DropDownList>

I fill in as in the following code:

if (!PostBack) {

this.ddlList.DataSource = CreateDataSource(this.List);
this.ddlList.DataTextField = "Name";
this.ddlList.DataValueField = "value";
this.ddlList.DataBind();


}

ICollection CreateDataSource(List<Vendor> vendorList)
{
    DataTable dt = new DataTable();

    dt.Columns.Add(new DataColumn("Name", typeof(string)));
    dt.Columns.Add(new DataColumn("Value", typeof(string)));
    dt.Columns.Add(new DataColumn("IsActive", typeof(bool)));

    foreach (var item in List)
    {
        dt.Rows.Add(CreateRow(item.DisplayName, item.Value, item.IsActive, dt));
    }
    DataView dv = new DataView(dt);
    return dv;
}


DataRow CreateRow(string Name, string Value, bool IsActive, DataTable dt)
{    
    DataRow dr = dt.NewRow();
                
    dr[0] = Name;
    dr[1] = Value;
    dr[2] = IsActive;

    return dr;
}

No problem to get the values on c# side this way but how to do in JS or Jquery?

var test = (DataView)this.ddlList.DataSource;
var test2 = test[i].Row["nameOfRow"]; //i is the index of the line 

Thanks in advance

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!