Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to bind the values in dropdown list compare to other dropdownlist ..please anyone can help me its urgent.....?
Posted

1 solution

1) Below is the code to bind the values in dropdown list. Lets say the datasource for this drop down list is a DataTable with columns ID and Name

C#
public void PopulateDropDown(DataTable dt)
{
    DropDownList1.DataSource = dt; 
    DropDownList1.DataTextField = "Name"; 
    DropDownList1.DataValueField = "ID"; 
    DropDownList1.DataBind(); 

}

2. Now to compare the two dropdownlist, you need to compare the there datasource, which in our case is datatable.

C#
// The parameters for this function are the two datatables.
// Both these datatable should have identical columns for this function to work.
// You can call another function to compare the columns, before calling this 
// function 
public bool AreDataTableMatching(DataTable dt1, DataTable dt2)
{
    DataTable dt = new DataTable();   
    dt = dt1

    // this will add to dt1 any records that are in dt2 but not dt1 return
    dt.Merge(dt2); 

    // returns records originally only in dt2
    dt.GetChanges();  

    if (dt.Rows.Count > 1)
        return false;
    else
        return true
}
 
Share this answer
 

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