How to insert an "empty" string in a DataTable?

I am using the DevExpress control LookUpEdit. There are two tables in my database that control a set of control parameters. One is called MaintCategory and one is called MaintItem. This introduces the Magic Number into my program (CategoryID), but allows me to adjust the runtime a lot.

My problem is how to allow my users to cancel the drop-down menu WITHOUT me in order to add an “empty” item for each CategoryID. There is no way to enter an empty string? At the management level or when building DataTableto return?

This is the DAL method that I use to populate all control options.

public static DataTable GetMaintItems(int iCat)
    {
        using (var context = CmoDataContext.Create())
        {
            IQueryable<tblAdminMaintItem> tItems = context.GetTable<tblAdminMaintItem>();

            return (tItems.Where(item => item.CategoryID == iCat & item.Active == true).OrderBy(item => item.OrderID).Select(
                item => new { item.ItemID, item.ItemDescription })).CopyLinqToDataTable();
        }
    }
+3
3

, , DevExpress LookUpEdit control - .

:

  • LookUpEdit.Properties.AllowNullInput true.
  • LookUpEdit.Validating.
  • Text EditValue null .

, - :

void m_lookUpEdit_Properties_Validating(object sender, CancelEventArgs e)
{
    if (string.IsNullOrEmpty(m_lookUpEdit.Text))
    {
        m_lookUpEdit.EditValue = null;
    }
}

reset null.

+3

Why don't you try something like this:

    dropdown.DataSource = GetMaintItems(x);
    dropdown.DataTextField = "Name";
    dropdown.DataValueField = "ID";
    dropdown.DataBind();
    dropdown.Items.Insert(0, new ListItem("Select item", "-1"));

Thanks Flores

0
source

Source: https://habr.com/ru/post/1770102/


All Articles