Navigation: DbNetComboCore >

Constructors

 

 

 

 

DbNetComboCore is server-side ASP.NET Core combo/select component designed to be used in a Razor view.

 

The constructor accepts up to 5 arguments

 

...

@(new DbNetComboCore("northwind", "customers", "customerid", "companyname").Render())

...

 

 

Connection - The name of the database connection string in the application appsettings.json file. (required)

FromPart - The name of the table or view from which the data is selected (required)

ValueColumn - The name of the column that contains the value of the combo option (required)

TextColumn - (optional) The name of the column that contains the text of the combo option (if not supplied then the ValueColumn is used)

Id - (optional) Specifies the Id of an existing element on the page that want the control to be rendered inside of (if not supplied the control is rendered at the point in the view where the Render method is called.

DataSource - (optional) Specifies the type of data source source. Either TableOrView (default) or StoredProcedure

Demo

 

Constructor when rendering in an exisiting HTML element

 

...

<div class="source">

    <div class="row">

        <div class="col">

            <h5>Artist</h5>

            <div id="artists"></div>

        </div>

        <div class="col">

            <h5>Album</h5>

            <div id="albums"></div>

        </div>

        <div class="col">

            <h5>Track</h5>

            <div id="tracks"></div>

        </div>

    </div>

</div>

...

 

Note the 5th (optional) parameter specifies the Id of an existing HTML element inside of which the grid will be rendered

 

...

DbNetComboCore tracksCombo = new DbNetComboCore("chinook", "tracks", "trackid", "name", "tracks") { ForeignKeyColumn = "albumid", EmptyOptionText = "Please select a track ..." };

DbNetComboCore albumsCombo = new DbNetComboCore("chinook", "albums", "albumid", "title", "albums") { ForeignKeyColumn = "artistid", EmptyOptionText = "Please select an album ..." };

DbNetComboCore artistsCombo = new DbNetComboCore("chinook", "artists", "artistid", "name", "artists") { EmptyOptionText = "Please select an artist ..." };

albumsCombo.AddLinkedControl(tracksCombo);

artistsCombo.AddLinkedControl(albumsCombo);

@artistsCombo.Render()

...

 

Demo

 

Constructor when using a stored procedure as a data source

 

...

DbNetComboCore inactiveCustomers = new DbNetComboCore("sakila", "GetAllCustomers", "customer_id", "email", null, DataSourceType.StoredProcedure);

inactiveCustomers.ProcedureParams["isActive"] = 0;

inactiveCustomers.Size = 20;

@inactiveCustomers.Render()

...

 

Any parameters accepted by the stored procedure can be assigned using the ProcedureParams property

 

 

Specifying the database type in the constructor

 

If you are using a database other than MS SQL Server or SQLite which have their Data Providers included in the .Net Framework then you will need to install the required Data Provider for the database you are connecting to and to also specify the type of database in the constructor

 

...

DbNetComboCore customersCombo = new DbNetComboCore("sakila", DatabaseType.MySQL, "customers", "id", "company");

@customersCombo.Render()

...

 

 

 

 

 

Copyright © 2023 DbNetLink