Select theme:
There are two kind of properties in Radzen - page properties and component properties.
Page properties store application data: the result of a database query, user input (the text your users type), or any other data needed by the developer.
Global properties are similar to Page properties however are available in all pages of the application.
Component properties configure the behavior - the text that a Button displays, the items of a DataGrid.
Component properties can be set to page properties. In this case we say that the component property is data-bound to a page property.
To create a page property handle the Load event of the current page and use the Set property action. You must set the property Name (so you can refer to it later) and Value.
counter
and Value to 0
. This creates the counter property and sets its value to zero.A page property maps to a C# class property in Blazor applications. Thus it obeys to certain naming restrictions:
new
, class
, bool
, var
etc.A common task is to display a property value to your application users. In Radzen this is done by data-binding a component property to a page property.
The Label component can display a text or number property (like the one we created in the Create property section).
counter
property and click OK. This sets the Text property of the label to ${counter}
.Now the Text of the Label component is data-bound to the counter page property. If the counter property changes the text of the label will update and display the latest value.
But what is this ${counter}
syntax? This is called an expression.
Expressions have a few important usages:
The example above produces the following Blazor code when you run the application: <RadzenLabel Text="@($"{counter}")" />
.
The Expressions article contains more info about expressions.
To update the value of a property you have to use the Set property action again. Let's add a Button which updates
the property value. The counter
property will increment whenever the user clicks the button.
Increment
. Note that we did not use ${Increment}
this time. We set the Text of the button to the literal value Increment
.counter
and Value to ${counter} + 1
;Run the application. Clicking the button increments the counter
property and the label displays its current value. This happens because the Text of the Label is data-bound to the counter
property via the ${counter}
expression.
The ${counter} + 1
expression is what increments the value of the counter
property. It generates the following C# code counter = counter + 1;
.
More info about the Set property action and the other action types supported by Radzen is available in the Event handling article.
Getting the user input in a page property is another common task in Radzen applications. The component that can do that are: TextBox, Numeric, DropDown et. al.
The following example shows how to store the text the user types in a page property.
First add a page property that will store the text.
text
and Value to ""
(empty string). This creates a new page property called text whose value is ""
(empty string).Then add a TextBox component and data-bind its Value property to the text page property that you just created. The Value property of input components (such as the TextBox) is special. It updates the page property it is data-bound to when the user changes the component value (e.g. types something in the TextBox).
text
property. This data-bounds the Value of the TextBox to the text property of the page.The Blazor code that Radzen generates is this <RadzenTextBox @bind-Value="@text" />
.
Let's also display what the user typed!
Show text
.Text
and Detail You entered: ${text}
.Clicking the button displays the value of the text property. Let's run the application.
Getting data from a data source (database or other) and displaying it to your users is another common task. While scaffolding and the New Page wizard facilitate this a lot let's see what they do under the hood.
Use the Radzen sample data source by following the instructions from the Quickstart
Then invoke a method of the data source and store its result in a page property.
orders
and Value to ${result}
.
This will store the response of the getOrders
data source method (available as the result
implicit property) in the orders property.When the page loads it will invoke the getOrders method and then set the orders property to the response.
Here is what the generated C# code looks like:
var sampleGetOrdersResult = await Sample.GetOrders();
orders = sampleGetOrdersResult;
Let's show the orders in a DataGrid component.
When you run the application you should see a DataGrid showing all orders.
Since showing data in a DataGrid is a very common requirement Radzen offers a few shortcuts:
Radzen is free to use. You can also test the premium features for 15 days.
Download NowSelect theme: