How can I validate if atleast one item has been selected from a list, such that the selectedIndices is set to NULL at the init() of application?
Following code can be of help to someone who want to validate a list like I wanted:
<mx:NumberValidator
id ="myListValidator"
trigger ="{myButton}"
triggerEvent ="click"
minValue ="0"
lowerThanMinError="Should I write an application to you for selecting atleast one of the option X-("
source ="{myList}"
property ="selectedIndex"
/>
Related
Sorry if this is a Blazorise and not just a general Blazor WebAseembly question, being a noob in both I'm just not sure so posting with both tags, but I'd like to display a list of items in a DataGrid that has certain columns sortable (multiple simultaneously and not by just one at a time), and once that sortable columns desc/asc/none direction setting occurs I'd like to be able to read their set direction properties state on a button click to pass it along to another component...only I can't do it with a #ref like this:
<DataGrid TItem="Item"
Data="#ItemList"
#ref="dataGrid"
#bind-SelectedRow="#selectedItem"
Responsive ShowPager="true" PageSize="10">
<DataGridCommandColumn TItem="Item" />
<DataGridColumn TItem="Item" Field="#nameof(Item.Id)" Caption="#" Sortable="false" />
<DataGridColumn TItem="Item" Field="#nameof(Item.SKU)" Caption="SKU" Sortable="false"/>
<DataGridColumn TItem="Item" Field="#nameof(Item.ModelId)" Caption="Model" Sortable="false" />
<DataGridColumn TItem="Item" Field="#nameof(Item.Year)" Caption="Year" Editable="true" Direction="SortDirection.Ascending" />
<DataGridColumn TItem="Item" Field="#nameof(Item.Weight)" Caption="Weight" Editable="true" Direction="SortDirection.Ascending" />
</DataGrid>
#code {
private Blazorise.DataGrid.DataGrid<Ad> dataGrid;
protected void OnClick(MouseEventArgs mouseEventArgs)
{
int i = 0;
string sortdirections="";
dataGrid.DataGridColumns.
foreach(Blazorise.DataGrid.DataGridColumn<Ad> col in dataGrid.DataGridColumns)
{
if (col.Sortable)
{
i++;
switch(col.SortDirection){
case SortDirection.Ascending: smartsort += ("a" + i.ToString()); break;
case SortDirection.Descending: smartsort += ("d" + i.ToString()); break;
case SortDirection.None: break;
}
}
}
. . .
}
Because I get a build error
CS1579 foreach statement cannot operate on variables of type
'RenderFragment' because 'RenderFragment' does not contain a public
instance or extension definition for 'GetEnumerator'
given that the dataGrid.DataGridColumns seemingly doesn't reference the actual rendered instance of the dataGrid component I'm using (but a RenderFragment instead), because one should probably databind variables to those Direction properties I guess...but the trouble with me databinding Direction properties to some or particular variable(s) is that I'd like to make the DataGrid a bit more dynamic in the future, in which case I wouldn't even know in advance during design-time what and which columns would be sortable and the user could be setting some sortable columns to sort direction none...thus I need some (pardon the pun) direction please on how to do it this way (basically like using old ASP.NET server-side components to access its run-time state in a blazor webassembly app) or how to do it with preferably just a single databound variable dynamically but so that just a few columns out of the ones displayed are going to actually be sortable through a click on a datagrid column name with which the user could change the sort order direction (so that the databound variable then after the user finishes clicking the sort orders of colums holds the state of that datagrid indicating which of the sortable columns have been set to ascend and which of the to descend, if any of them, since they can also choose direction none)?
TIA
The latest version of Blazorise has a sort mode:
<DataGrid ... Sortable="true" SortMode="DataGridSortMode.Multiple" ...
https://blazorise.com/docs/helpers/enums/datagrid
If that's not exactly what you are looking for, ask Mladen on gitter or check out the source code here.
I may be having a blonde moment here.
I have a data entry form with the usual "Save" and "Cancel" buttons. In addition to these two I have another button "Approve". If the user clicks the "Approve" button I have an additional field (Approver) that must hold data. Is it possible to have a required field validator that is active on one button press but not another?
Yes This is possible :
You can Define multiple Validation group and decide witch group to validate depending on the clicked button, for that you should call javascript function onClientClient in order to validate the inputs :
See example bellow:
Triggering multiple validation groups with a single button
I think you will have to create a custom validator or just use javascript or jquery.
You can use the OnClientClick property of the buttons and add some javascript on there.
function CheckSave() {
if (/*text1 is filled*/) return true;
}
function CheckApprove() {
if (/*text1 is filled and text2 is filled*/) return true;
}
<asp:button id='btnSave' OnClientClick='return CheckSave()' OnClick='btnSave_Click' />
<asp:button id='btnApprove' OnClientClick='return CheckApprove()' OnClick='btnAprove_Click' />
you need the return in order for it to work
Page has Repeater Control displays students records, when click on any record it displays total info.
it has dropdown list displays list of all departments [ not static items ] comes from
db.<asp:DropDownList ID="ddl_name" runat="server" DataSourceID="Employee" DataMember="Technical"
DataTextField="Last_name"
DataValueField="Emp_code"
FirstItemText="Select Item"
FirstItemValue="0"
BoundColumnName="LastName"
BoundDataMember="DeptCode"
Clear="true"
/> Thanks...
by default it should display the first item..and when the user selects a department and save it, the page reloads and again it should show the default value.
You can do it via DropDownList.SelectedIndex property:
ddl.SelectedIndex = 0;
But I would recommend using Post-Redirect-Get instead and after a redirect-get you will have your dropdown set to default.
You may also try storing selected value in a variable or Session[""]
I have a drop down list that is populated in the page load event from a database table.
The drop down has a DataTextField set to a project name and the DataValueField set to the project id (interger).
Later I change the dropdowlist selected item with this code in the selectedindexchanged event of a gridview
GridViewRow row = GridView1.SelectedRow;
ddlProjectList.SelectedItem.Text = row.Cells[2].Text;
Does Changing the drop down list with this code cause the DataValueField property to change to the correct Project ID number also? If not is there a better way to do this?
=============================================EDIT
actually this code seems to be adding an additional item to the list so that the project i set with this code is listed twice so I don't think my code is correct
This does not change anything else than the text of the selected item in your DropDownList. Do you want to change the text and value of the project, or do you want to select the project from the DropDownList that relates to the selected row in the grid?
To change the project name and id, you'll have to change it in the data source behind the ProjectList. But if you just want to select the related project, you can use this:
var row = GridView1.SelectedRow;
if (ProjectList.Items.FindByText(row.Cells[2].Text) != null)
{
ProjectList.ClearSelection();
ProjectList.Items.FindByText(row.Cells[2].Text).Selected = true;
}
Setting SelectedItem.Text does not actually change the selected item by its text, it changes the text of the currently selected item. You need to use ddl.Items.FindItemByText (or it may be worded FindByText, I forget at the moment) to find the item, then set the ListItem.Selected property to true.
HTH.
You can do
ddlProjectList.FindByText(row.Cells[2].Text).Selected = true;
This will actually set it.
I have a Flex ComboBox that gets populated by a dataprovider all is well...
I would now like to add a default " -- select a item --" option at the 0 index, how can I do this and still use a dataprovider? I have not seen any examples of such, but I can't imagine this being hard...
If you don't need the default item to be selectable you can use the prompt property of ComboBox and set the selectedIndex to -1. That will show the string you set propmt to as the selected value until the user chooses another. It will not appear in the list of options, however.
I came across this problem today and wanted to share my solution.
I have a ComboBox that has an ArrayCollection containing Objects as it's dataprovider. When the application runs, it uses a RemoteObject to go out and get the ArrayCollection/Objects. In my event handler for that call I just have it append another object to the beginning of the ArrayCollection and select it:
var defaultOption:Object = {MyLabelField: "Select One"};
myDataProvider.addItemAt(defaultOption, 0);
myComboBox.selectedIndex = 0;
This is what my ComboBox looks like for reference:
<mx:ComboBox id="myComboBox" dataProvider="{myDataProvider}" labelField="MyLabelField" />
The way I've dealt with this in the past is to create a new collection to serve as the data provider for the combobox, and then I listen for changes to the original source (using an mx.BindingUtils.ChangeWatcher). When I get such a notification, I recreate my custom data provider.
I wish I knew a better way to approach this; I'll monitor this question just in case.
This can be used following code for selected default value of combobox
var index:String = "foo";
for(var objIndex:int = 0; objIndex < comboBox.dataProvider.length; objIndex++) {
if(comboBox.dataProvider[objIndex].label == index)
{
comboBox.selectedIndex = objIndex;
break;
}
}
<mx:ComboBox id="comboBox" dataProvider="{_pageIndexArray}" />