Hi,

I have three dropdownlist. I need help for how to bind the three dropdownlist in single query.I.e. Now i write the code was every time the datas coming from DB. But i need only one time the datas are come from Db, then we bind the dropdownlists at the same time. Anybody have any idea for this dropdown bind process?

WHY YOU NEED TO BIND SAME QUERY RESULT IN 3 DROP DOWN?? I can't undersatnd.

        DataTable dType = clsDbUtility.ExecuteQuery("Select * from source_datatype where active=1");
        cboSourceDataType.DataTextField = "description";
        cboSourceDataType.DataValueField = "id";
        cboSourceDataType.DataSource = dType;
        cboSourceDataType.DataBind();

clsDbUtility.ExecuteQuery its a custom method change it in your way.

ANOTHER WAY IS TO EASE YOUR LIFE BY DEVELOPING YOUR METHODS LIKE:

public static void FillCombo(DropDownList dropDownList, string dataTextField, string dataValueField, DataTable dataTbl, bool bHasBlank, bool bMandatory)
    {
        dropDownList.DataTextField = dataTextField;
        dropDownList.DataValueField = dataValueField;
        dropDownList.DataSource = dataTbl;
        dropDownList.DataBind();

        if (bHasBlank)
        {
            ListItem oItem = new ListItem();
            if (!bMandatory)
            {
                oItem.Value = "0";
                oItem.Text = "";
            }
            dropDownList.Items.Insert(0, oItem);
        }
    }

ADD A STATIC CLASS LIKE CLSUIUTILITY. THEN ADD THE ABOVE METHOD & USE IT FROM ALL OF YOUR PAGES.

WHERE FIRST ARGUMENT TAKES YOUR DROPDOWN OBJECT.....

KEEP EXPERIMENTING BY VARRING THE 4th & 5th column.
TRY TO ADD AN REQUIRED FIELD VALIDATOR WITH YOUR DROPDOWN LIST.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.