Change which field is displayed in a dropdown - asp.net

I have a Dynamic Data website and while inserting a record into a table, the foreign key relationship shown as a drop-down uses the wrong field for it's select item text value.
How can I change the drop-down such that when working with this one table, it will use a different column as the value in the drop-down?
thank you

The solution is to add a partial class with some attributes from the System.ComponentModel.DataAnnotations namespace & assembly. Notice the [DisplayColumn("Description")] below. That's what field is used to render as the text in a list.
Further reading
[MetadataType(typeof(ProductMetadata))]
**[DisplayColumn("Description")]**
[ScaffoldTable(true)]
public partial class Product
{
}
public class ProductMetadata
{
[UIHint("TextReadOnly")]
public string CreatedBy;
[UIHint("TextReadOnly")]
public string CreatedDate;
[ScaffoldColumn(false)]
public EntityCollection<OrderItem> OrderItem;
}

Related

Acumatica - Get multiple selected lines from grid in code behind

I am selecting multiple lines (ctrl/shift+click) from the grid on the Sales Order screen and want an action to have access to what was selected. How do I access the list of what's selected on the grid from the code behind?
As stated, add the selected screen. First you would add a DAC extension to add the selected field, which is not a DB field.
#region Selected
[PXBool]
[PXUIField(DisplayName = "Selected")]
public virtual bool? Selected { get; set; }
public abstract class selected : PX.Data.BQL.BqlBool.Field<selected> { }
#endregion
From there, you can add the selected field to your table in the UI. Also, ensure that commit changes is set on that field, or an action that you may call to query.
Finally, you can just run a foreach for the view, and check for the selected field you added:
foreach (SOLine line in Base.Transactions.Select())
{
SOLineExt lineExt = line.GetExtension<SOLineExt>();
if (line.Selected == true)
{
//execute code on the record
}
}

kentico page title from custom table

I have a page in Kentico that displays data from a custom table. One of the custom table fields is page title, and I can't figure out how to display the page title field in the...
<title></title>
...tags
The closest thing I can get to it is displaying part of the uri as the title, so /promo/page-title will create a title of
<title>page-title</title>
Wich is less than desirable for three reasons:
/promo/pAgE-TItle will display the title as pAgE-TItle
the dashes are still there from the url
The text from the uri is actually just a slug that represents the data in the custom table (a field named programkey) and is Not always the same as the actual title of the data
(EDIT)
Ok thanks to Raymond, and a bit of fumbling around, this is what I found works (posted in a custom table transformation):
<script runat="server">
private string Title { get; set;}
private string Description { get; set;}
private string Keywords { get; set;}
    protected override void OnDataBinding(EventArgs e)
    {
base.OnDataBinding(e);
// Get values from custom table
Title = DataBinder.Eval(this.DataItem, "seo_title").ToString();
Description = DataBinder.Eval(this.DataItem, "seo_desc").ToString();
Keywords = DataBinder.Eval(this.DataItem, "seo_keywords").ToString();
// Set values in meta tags
CMSContext.CurrentTitle = Title;
CMSContext.CurrentDescription = Description;
CMSContext.CurrentKeyWords = Keywords;
}
</script>
You can also create a custom macro in which you will use the API to get the custom table data. Then, use this macro in the page title/metadata settings
This should do the trick:
CMSContext.CurrentTitle = "asdasd";

DevExpress GridViewDataComboBoxColumn displaying value(id) instead of text in display mode

I am using a DevExpress ASPxGridView containing column GridViewDataComboBoxColumn.
The combo box is working correctly in edit mode (allows AJAX style filtering; it inserts, updates and deletes correctly).
The only problem is that in display mode it is displaying the ValueField (numeric id) instead of the TextField.
<dx:GridViewDataComboBoxColumn Width="200px" FieldName="LocationKeyUid" VisibleIndex="0" Caption="Index">
<PropertiesComboBox EnableCallbackMode="true" CallbackPageSize="7" IncrementalFilteringMode="StartsWith"
OnItemsRequestedByFilterCondition="ItemsRequestedByFilterCondition" OnItemRequestedByValue="ItemsRequestedByValue"
TextField="KeyValue" ValueType="System.Int32" TextFormatString="({0}) {1}" ValueField="LocationKeyUid" />
As shown above, I've tried different experiments with setting the TextFormatString, but that seems to be ignored.
I am binding as follows:
IList<LocationKeyGridViewModel> locationKeys = GetLocationKeys();
locationKeyGridView.DataSource = locationKeys;
locationKeyGridView.DataBind();
The class property names (below) are assigned to the TextField and ValueField property settings (above).
public class LocationKeyGridViewModel
{
public int LocationKeyUid { get; set; }
public string KeyValue { get; set; }
}
I have tried changing the FieldName property assignment to the TextField assignment
(i.e. KeyValue) but that generates an Input string is not in correct format error.
Is there something obvious here that I am missing?

How to override label using EditorTemplate?

For a string property in MVC3, I've created a partial view at ~/Shared/EditorTemplates/String.cshtml and I've placed within it the following:
#model System.String
<div class="Input">
#Html.TextBox("", this.Model)
#Html.ValidationMessage("")
</div>
Viewing the result, it looks good. But the label is still showing up. As you can see it's not included in the partial view, above, so it must be coming from the base view.
How do I override the label output so when I do #Html.EditorForModel(), my string properties will have a customized label?
Use System.ComponentModel.DisplayName attribute to override the member name.
For example:
public string MyProperty {get;set;} //displays "MyProperty"
[DisplayName("My Property")]
public string MyProperty {get;set;} //displays "My Property"
I ended up creating a custom Object.cshtml template.

How to add custom property to asp.net custom server control?

I have created an asp.net custom control and now want to pass some values to it from the page which will use the control.Is there any way i can add my own property to the control (like Text property is present for a Label control) ?
It's a class. Add a public property to it.
Assuming ASP.NET 3.5+ just create properties
public string YourProperty {get; set;}
Would be declarative on the control
Adding a property to a custom control in asp.net is no different than adding a property on any class in C# (for instance).
public class Custom : Control
{
public string Text { get; set; }
}
just add it as public property, then it should be useable for your needs.

Resources