locked
Add multi-column values to a Dropdown control RRS feed

  • Question

  • User175729676 posted

    Hi,

    An aspx page is consuming a "Query service" of MS Dynamics AX.

    The query has two tables a customer table and a party table which are related.

    The customer table has the customer ID (account num) field and the party table has the "Name"field.

    I have a dropdown control as:

    dataSet = client.ExecuteQuery(query, ref paging);
    listCustomers.DataSource = dataSet.Tables["CustTable"];
    listCustomers.DataValueField = "AccountNum";
    listCustomers.DataTextField = "AccountNum";
    listCustomers.DataBind();

    I want to display values in the dropdown as:

    listCustomers.DataTextField = "AccountNum" + " " + "Name";

    How could I achieve this?

    Any help is appreciated!

    Regards,

    Abhinay

    Friday, November 23, 2018 8:31 AM

Answers

  • User-1716253493 posted

    You can add ddl items manualy

    listCustomers.Items.Add(new ListItem("name", "value"));

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 26, 2018 12:44 AM

All replies

  • User-1716253493 posted

    Combine it in sql query instead

    SELECY AccountNum + ' ' + Name as NumName
    listCustomers.DataTextField = "NumName";

    Friday, November 23, 2018 12:54 PM
  • User1281381861 posted

    Correct, bring it from SQL itself.

    Saturday, November 24, 2018 3:16 PM
  • User175729676 posted

    Combine it in sql query instead

    It is a static query in MS Dynamics ERP and I can only execute the query using a query service.

    Regards,

    Abhinay

    Sunday, November 25, 2018 1:40 PM
  • User-471420332 posted

    <br>
    while binding dropdown text value you can bind like this way also..&lt;br&gt;<br>
    &lt;br&gt;<br>
    listCustomers.DataTextField = "AccountNum"+"+newcolumnvalue+";
    Sunday, November 25, 2018 5:07 PM
  • User-1716253493 posted

    You can add ddl items manualy

    listCustomers.Items.Add(new ListItem("name", "value"));

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 26, 2018 12:44 AM
  • User61956409 posted

    Hi Abhinay,

    You can loop over the row of dataSet.Tables["CustTable"].Rows, and dynamically add item to your DropDownList control.

    foreach (DataRow row in dataSet.Tables["CustTable"].Rows)
    {
        listCustomers.Items.Add(new ListItem() {
            Value = row["AccountNum"].ToString(),
            Text = row["AccountNum"].ToString() + " " + row["Name"].ToString()
        });
    }

    With Regards,

    Fei Han

    Monday, November 26, 2018 2:26 AM
  • User175729676 posted

    Thanks! This is how I did it:

    foreach (DataRow dr in dataSet.Tables[0].Rows)
    {
        DataRow[] foundRows = dataSet.Tables[1].Select("RecId = " + dr["Party"]);
    
        foreach (DataRow drParty in foundRows)
        {
            string NameStr =  dr["AccountNum"] + ":" + drParty["Name"].ToString();
            string custNum = dr["AccountNum"].ToString();
            ddlCustomers.Items.Add(new ListItem(NameStr, custNum));
        }    
    }

    Monday, November 26, 2018 7:06 AM