lookup replaces field lookup (v2023)

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
crash
User
Posts: 151

lookup replaces field lookup (v2023)

Post by crash »

Using ASPNM23
I'm using the standard code

public void Lookup_Selecting(DbField fld, ref string filter) {
    if (fld.Name == "MyLookupField") {
        fld.Lookup.UserSelect = "SELECT Field1 AS lf, Field2 AS df, Field3 AS df2, '' AS df3, '' AS df4 FROM Table1"; // Modify SELECT
        fld.Lookup.UserOrderBy = "Field2 ASC"; // Modify ORDER BY
    }
}

I'm trying to display additional fields in the lookup but save only the first two field in the table, but all four fields in my lookup get captured and overrides the field lookup,
How do I save only the first two fields even if lookup displays four fields.

Thanks


MichaelG
User
Posts: 1110

Post by MichaelG »

Lookup should save the link field (lf) to the database only.


crash
User
Posts: 151

Post by crash »

Thanks I've manged to get it to show only lf... when i save it shows in the view page... but now when I go back to edit page the record is empty and have to enter again.
both fiels are VarChar..


MichaelG
User
Posts: 1110

Post by MichaelG »

If you mean you want to show different value for lookup in view page, use the Row_Rendered server event.


crash
User
Posts: 151

Post by crash »

no I mean that when you save the field the record shows in view... but when you then go back to edit the record disappears from the field, then have to re-enter the records. and then save again


MichaelG
User
Posts: 1110

Post by MichaelG »

You should simply:


crash
User
Posts: 151

Post by crash »

I have checked the fields match the sequence of the fields in the lookup code match the fields in the aspnm field lookup table, i tried removing the fields, tried changing the link field, no matter what I do when i go back to the edit after a successful save, the records do not show and I have to re-enter.
Fields that do not use the code works and shows the old record.


MichaelG
User
Posts: 1110

Post by MichaelG »

You do not need the Lookup_Selecting codes. You should simply set up your lookup settings for use in the add/edit page and use the Row_Rendered server event to change the display value for the list/view page.


crash
User
Posts: 151

Post by crash »

Row rendered seems to only modify css...


MichaelG
User
Posts: 1110

Post by MichaelG »

You can modify the field view value by:

Field.ViewValue = "<new value>";

crash
User
Posts: 151

Post by crash »

Thanks but then there will still be a value.. I just want to hide the last two display fields


MichaelG
User
Posts: 1110

Post by MichaelG »

You should get the row data and format on your own. For example:

var row = ExecuteRow("SELECT DisplayField1, DisplayField2 FROM LookupTable WHERE LinkField = ...");
Field.ViewValue = Convert.ToString(row["DisplayField1"]) + ", " + Convert.ToString(row["DisplayField2]);

crash
User
Posts: 151

Post by crash »

When I go back to edit my record it’s empty.


MichaelG
User
Posts: 1110

Post by MichaelG »

Show you complete lookup settings and all the server event codes you are using.


Post Reply