0

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?

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by mail2saion
0

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.

Edited by mike_2000_17: Fixed formatting

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.