Conditionally hide DeleteButton in GridViewCommandColumn - vb.net

I have ASPxGridView to view a list of records. From the view, I create a delete column and want it to show a delete button whenever the record does have a satisfy condition. The code below:
<dx:GridViewCommandColumn Caption="Delete" VisibleIndex="1" Width="30px"
meta:resourcekey="GridViewCommandColumnResource1">
<DeleteButton Visible="True">
</DeleteButton>
</dx:GridViewCommandColumn>
So I focus on the Visible attribute of DeleteButton. The condition must return a boolean value so it knows when to show and hide the delete button. Below is an example how to implement this:
<DeleteButton Visible='<%# ShowHide(Eval("Active")) %>'>
</DeleteButton>
in VB Code:
Protected Function ShowHide(Active As Boolean) As Boolean
Return Active
End Function
So the function need to return a True value if Active is True, and False value if Active is False. In other words, I do trigger a function in code behind on every record to make it show the delete button if record does have a satisfy condition. But I got an error message in the end:
Parser Error Message: Databinding expressions are only supported on objects that have a DataBinding event. DevExpress.Web.ASPxGridView.GridViewCommandColumnButton does not have a DataBinding event.
I stuck there and don't know other way to do this. Please help me with this.

After a night to research on this, I have find a new way to solve this issue:
This block of code from aspx file within an ASPxGridView:
<dx:GridViewCommandColumn Caption="Delete" VisibleIndex="1" Width="30px"
meta:resourcekey="GridViewCommandColumnResource1">
<DeleteButton Visible='True'><!--TRI - 20160329 Please make sure the Visible attribute always True-->
</DeleteButton>
</dx:GridViewCommandColumn>
From the code behide, I implement an initial method to handle a trigger on DeleteButton:
Protected Sub xgv_CommandButtonInitialize(sender As Object, e As DevExpress.Web.ASPxGridView.ASPxGridViewCommandButtonEventArgs) Handles xgv.CommandButtonInitialize
If e.ButtonType = DevExpress.Web.ASPxGridView.ColumnCommandButtonType.Delete Then
If sender.GetRowValues(e.VisibleIndex, "Active") = True Then
e.Visible = False
End If
End If
End Sub
The method will handle the DeleteButton by checking the Active value on Command Button Initialize. If the Active is True, it will hide the DeleteButton and vice versa.

You could either handle the ASPxClientGridView.CustomButtonClick Event as shown here : Link or Place your custom control into GridViewDataColumn.DataItemTemplate : Link

Related

Validate if checkbox is checked depending on another validation in vuelidate

I'm just starting with Vue and vuelidate. I have a form which shall work in the following way:
The form shows a Yes/No radio button group.
If the radio button "Yes" is selected then the form shows a checkbox.
The submit button for the form shall be enabled if one of the following conditions is true:
The radio button is set to "No". OR
The radio button is set to "Yes" AND the checkbox is checked.
I'm having trouble with the conditions described in 3. My current validation looks like this:
termsAccepted: { checked: value => value === true }
This basically works for case 3.2 but not for 3.1. In that case the form is still disabled.
b-form-checkbox#termsAccepted(
v-model="termsAccepted"
:state="!$v.termsAccepted.$invalid"
:disabled="disableForm"
)
Thats sound like a computed property should to the job:
Computed Property Documentation
You could do something like:
computed: {
isEnabled() {
return !radiobutton || (radiobutton && checkbox.checked)
}
}

Changing input type=text to type=submit with javascript trigger the submit

i'm trying to code form where you can navigate inside with a next button ( who will hide the current fieldset and show the next one ) and a previous one ( who will hide the current fieldset and show the previous one ). Those two input have a onclick function that will change the fieldset className to active from inactive depending on which fieldset we are. I want to change the next button input type when the user reach the final fieldset so he can submit, but it seems that it automatically trigger the submit event, which means when the user get to the final fieldset, he cant fill any input because the form will submit automatically.
So here's the code :
//When the last fieldset show
if (fieldset[4].className == "active") {
var next = document.getElementById('next');
next.onclick='';
next.type="submit";
next.value="Submit";
next.id='submit';
}
Is there something that i should add to stop the submit auto-firing ?
I've tested your code in JSFiddle and it works good. It means there is something that trigger submit. May be you can post whole javascript in that page and then I can check what is the issue.
var next = document.getElementById("next");
//next.type="submit";
next.setAttribute('type', 'submit'); // I prefer using .setAttribute method
next.onclick='';
next.value="Submit";
next.id='submit';
<form>
<input name="q" value="hello">
<input type="text" id="next">
</form>
I think instead of trying to "hack" the existing button and turn it into the submit, you could just have two buttons, one "next" and another one "submit-button" (hidden initially), once the user advances to the final step, you can hide the "next" button and show the "submit-button" button.
It can be something like this:
//When the last fieldset show
if (fieldset[4].className == "active") {
// hide the next button
document.getElementById('next').style.display='none';
// show the submit button
document.getElementById('submit-button').style.display='';
}
And it would be not complex to make these buttons to appear exactly on the same place with css, so the user will not notice the replacement.
There are browsers who do not allow you to change the type for security reasons. So you will often have problems with it. Just switch between two inputs as boris mentioned (or replace it completely). But to answer your question:
You can catch the autosubmit with another on submit event. First on click mark the button with a class or data attribute like "preventSubmit". Within the submit event check if this class or data attribute exists and prevent the submit (f.ex with prevent default()) and remove the class that all wanted submits by users clicks are not stopped.
Why not just add an event to submit the form you are currently on:
if (fieldset[4].className == "active") {
var next = document.getElementById('next');
next.onclick=(function() { document.forms[0].submit(); });
//next.type="submit";
next.value="Submit";
next.className="MySubmit"; // try to style it as a button for better UX
//next.id='submit';
}

Accessing RadListBox Items in Code-Behind

I have the following RadListBox:
<telerik:RadListBox ID="AttachmentsRadListBox" CheckBoxes ="true" runat="server" />
It is located in a RadWindow, therefore I am populating it through the following code which is only called when RadWidnow becomes visible:
AttachmentsRadListBox.DataSource = AttachDT
AttachmentsRadListBox.DataTextField = "DocumentPath"
AttachmentsRadListBox.DataValueField = "DocumentID"
AttachmentsRadListBox.DataBind()
For Each item As RadListBoxItem In AttachmentsRadListBox.Items
item.Checked = True
Next
So far so good, the RadListBox is populated and all the items are checked.
Now, there is a Save button on the RadWindow when pressed before closing the window I am trying to read the checked items in the AttachmentsRadListBox (Since the user might have changed the status of the checked items). But every effort on reading the items has failed, for example on the Save button click I have the following:
Dim test As Integer = AttachmentsRadListBox.Items.Count // THIS IS ZERO
For Each item As RadListBoxItem In AttachmentsRadListBox.Items // THERE ARE NO ITEMS
If Not item.Checked Then
Dim DocumentIDToDelete As Integer = item.Value
End If
Next
Why is that the last piece of code does not behave as I hope? The AttachmentsRadListBox is not being bounded again through the postback. The only time that it is bounded is when the RadWindow appears. Then the Save button on the RadWindow obviously creates a postback but I don't understand why AttachmentsRadListBox contains no item at that point.
Since you create the AttachmentsRadListBox dynamically, do you recreate it on subsequent postbacks? It is, in the end, a server control, so you need to make sure it is recreated, because otherwise ASP will destroy it upon a subsequent postback.
To see how you can access controls in the ContentTemplate of a RadWindow you can also examine this article: http://www.telerik.com/help/aspnet-ajax/window-controls-container.html.

Binding Custom object to Checkbox in VB.NET

I am trying to bind a checkbox to a custom object boolean property as follows:
chkTableIsReadonly.DataBindings.Add(New Binding("Checked", objectBindingSource, "ApplyforVisa", True, DataSourceUpdateMode.OnPropertyChanged, False))
The custom class supports the INotifyPropertyChanged interface.
Everything works find when I initially bind the checkbox to a new object:
objectBindingSource.Datasource = new objectToBindTo
Here is the odd part:
If I check the box, the property Set gets called and the INotifyPropertyChanged event gets called and everyone is happy.
If I uncheck the same box, the property Set doesn't get called, the INotifyPropertyChanged event never gets called and (the worse part), I cannot navigate to another record.
I have tried capturing the CheckedChanged event to set the object.ApplyForVisa property manually, but no success. The property Set gets called and the INotifyPropertyChanged event gets called, but I am still locked on control and can't navigate.
I have tried calling bindingsource.endedit in the CheckedChanged event, no success.
It only matters if I uncheck the box. The checkbox is two-state - true or false.
All of my other bindings work just fine - text boxes, combo boxes, datagrid. Just not checkbox.
My only thought is that is seems to act like a binding source data error, but no error is thrown. If I add the data error event handler for the binding source, it never gets called.
Assuming the ApplyForVisa property is a Boolean, you can just fix this by setting formattingEnabled parameter for the Binding to False.
chkTableIsReadonly.DataBindings.Add( _
New Binding("Checked", objectBindingSource, "ApplyforVisa", _
False, DataSourceUpdateMode.OnPropertyChanged, False))

How to filter flex datagrid with three check boxes.?

I am new to flex.
I need your help. Can anyone help me please.
My Requirement:
Flex Datagrid should be filter based on 3 checkboxes.(Checkboxes can be checked with several combinations).
My Code:
Checkboxes:
Data Provider:
MXML code:
Here i have to filter the datagrid when i check the different combinations of 3 checkboxes.
The checkbox values are from Staus column of arraycollection.
When i select 'completed' checkbox and 'onhold' check box, datagrid should display only those records which have Status as "Completed" & "On Hold".
Similarly for all combinations of c
Can anyone give simple solution please ?
Thanks,
Anand.k
Use an ArrayCollection as your dataProvider and assign a filtering function to its filterFunction property :
var provider:ArrayCollection;
At the part where you instantiate your array, give it a filterFunction :
provider.filterFunction = myFilteringFunction;
With the code of the filterFunction like this :
private function myFilteringFunction(item:ObjectTypeInYourArray) : Boolean {
var show:Boolean;
if(item.completed == checkBox1.checked &&
item.onHold == checkBox2.checked){
show = true;
}
return show;
}
It's an example with two checkboxes. The type of value assigned to the completed and onHold attributes of your object may not be boolean so you'll have to convert them somehow before comparing them to the state of the checkboxes but I think you get the idea.
Basically the filterFunction that you pass to your arraycollection is applied to each of the items inside and return true or false depending on you code inside (e.g check if the object has the right values for its properties). When true the values are showed
At the change events of your checkboxes, you refresh the dataProvider :
provider.refresh();
Hope that helps