Nullable Datetime field not getting rendered in Store (Ext.Net) - datetime

<ext:Store ID="StoreSample" runat="server" RemotePaging="true" RemoteSort="true" AutoLoad="true"
ShowWarningOnFailure="false" >
<Proxy>
<ext:HttpProxy Url="~/Samples/OpenEdit/GetSampleList" Json="true">
</ext:HttpProxy>
</Proxy>
<Reader>
<ext:JsonReader IDProperty="Id" Root="data">
<Fields>
<ext:RecordField Name="Id" Type="Int">
</ext:RecordField>
<ext:RecordField Name="SampleDescription" Mapping="Description">
</ext:RecordField>
<ext:RecordField Name="SampleStartDate" Mapping="StartDate" Type="Date">
</ext:RecordField>
<ext:RecordField Name="SampleEndDate" Mapping="EndDate" Type="Date" >
</ext:RecordField>
</Fields>
</ext:JsonReader>
</ext:Store>
In this store the fields SampleStartDate and SampleEndDate are of type Nullabe Datetime (Datetime?) in the model. In controller i am getting value for every field and i am converting this to StoreResult in the function GetSampleList. But in store i am always getting the value as 'undefined' in these two fields. But if i change the datatype from Datetime? to DateTime the in model i am getting all the values in store.
Can any one help me to get the nullable datetime value in store?
i am using this store in GridPanel
<Sample:GridPanel ID="GridPanelSample" runat="server" StoreID="StoreSample" Header="false"
AnchorHorizontal="right" AnchorVertical="96%" StandardPager="true" MonitorResize="true" TabIndex="15">
<TopBar>
</TopBar>
<ColumnModel>
<Columns>
<ext:Column runat="server" ColumnID="SampleDescription" Header="Description"
DataIndex="SampleDescription">
</ext:Column>
<ext:DateColumn runat="server" ColumnID="SampleStartDate" Header="StartDate"
DataIndex="SampleStartDate" Format="d MMM Y">
</ext:DateColumn>
<ext:DateColumn runat="server" ColumnID="SampleEndDate" Header="EndDate"
DataIndex="SampleEndDate" Format="d MMM Y">
</ext:DateColumn>
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true"
MoveEditorOnEnter="true">
</ext:RowSelectionModel>
</SelectionModel>
<View>
<ext:LockingGridView runat="server" ID="gridview1" />
</View>
<Listeners>
<ViewReady Handler="openEdit.setOpenEditGridColumnWidths();"></ViewReady>
</Listeners>
</Sample:GridPanel>
But SampleStartDate and SampleEndDate column is always empty

I think you need to configure the .DateFormat property of the <ext:RecordField>.
Example
<ext:RecordField Name="lastChange" Type="Date" DateFormat="M$" />
Setting .DateFormat="M$" will automatically parse the "/Date(123...)/" value into a JavaScript Date object.
Hope this helps.

Finally i found the solution.
It was because i didn't covert the date type. It was always returning Microsoft AJAX serialized dates (Eg "/Date(1313467512730+0530)/"). This date i need to convert like "2011-08- 15T00:00:00:000". For this i used convert handler.
Code is like
<ext:RecordField Name="SampleStartDate" Mapping="StartDate" Type="Date">
<Convert Handler="return new Date(parseInt(value.substr(6)))" />
</ext:RecordField>
Then i am getting the nullable datetime field values in store.
Hope it will help you also
Thanks

Related

How to disable past dates in GridViewDataDateColumn in aspxgridview

<dx:GridViewDataDateColumn FieldName="ScheduledTimeForDelivery" Caption="Scheduled Time For Delivery" Width="14%" VisibleIndex="5">
<Settings AutoFilterCondition="Contains" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Font-Bold="True" Wrap="True" />
<PropertiesDateEdit DisplayFormatString="dd/MM/yyyy hh:mm tt" EditFormatString="dd/MM/yyyy hh:mm tt">
<TimeSectionProperties Visible="true">
<TimeEditProperties EditFormatString="hh:mm tt" EditFormat="Custom"></TimeEditProperties>
</TimeSectionProperties>
<ValidationSettings RequiredField-IsRequired="true" ErrorTextPosition="Bottom" ErrorDisplayMode="Text">
<RequiredField ErrorText="Please enter the Scheduled Time For Delivery" />
</ValidationSettings>
</PropertiesDateEdit>
<EditFormSettings VisibleIndex="3" />
</dx:GridViewDataDateColumn>
I want to disable all previous dates in my Column"ScheduledTimeForDelivery" how to disable it previous dates.
Reference: ASPxGridview - date column
Use the editor's MaxDate and MinDate properties for this purpose. For example:
GridViewDataDateColumn dateColumn = gridView.Columns["ScheduledTimeForDelivery"] as GridViewDataDateColumn;
dateColumn.PropertiesDateEdit.MaxDate = System.DateTime.Now.AddYears(5);
dateColumn.PropertiesDateEdit.MinDate = System.DateTime.Now.AddYears(-5);
Or you can manage to do it in aspx page also with help of documentation..
Disabling specific dates in ASPxDateEdit, in Edit form of ASPxGridView
Hope this help..
use this line in cell editor initialize even
if (e.Column.FieldName == "ScheduledTimeForDelivery")
(e.Editor as ASPxDateEdit).MinDate = DateTime.Now.Date;

Using Codefluent entitycollection with Infragistics WebHierarchicalDataGrid

I'm looking for some help on binding a Codefluent entitycollection with an Infragistics WebHierarchicalDataGrid (v14.2). For illustrative purposes, I have two Codefluent entities: Customer and Order; where one related customer has many related orders.
On my ASP page, I have created the WebHierarchicalDataGrid, the WebHierarchicalDataSource, and two objectDataSources. For the WebHierarchicalDataSource I created two DataViews along with their DataRelations. The WebHierarchicalDataGrid's DataMember, Key, and DataKeyFields are all set correctly.
If the objectDataSources SelectMethods are set to the LoadAll methods of the CustomerCollection and the OrderCollection, the WebHierarchicalDataGrid displays as expected - that is the customer rows have nested order rows in the grid, and clicking on the +expansion icon displays the customer's order rows.
What I am trying to do is display the WebHierarchicalDataGrid for a single customer based on a user's input in a textbox on the webpage.
In the code behind I set the Customer's objectDataSource's SelectMethod to a method (LoadByCustomerID) defined in the Codefluent model which contains one paramameter (CustomerID) which I set to the value from the text box. I then call the Customer's objectDataSources Select method. This returns the desired Customer entity as expected.
From the returned Customer entity, I use data from a field (GUID) in the Customer entity to supply the SelectMethod (LoadOrdersByCustomerGUID) of the Order's objectDataSources. This too returns the expected OrderCollection of one or more related customer orders.
The results displayed in the WebHierarchicalDataGrid is only that of the parent row (the selected Customer). There is a +expansion icon displayed in the Customer row, but clicking on the +expansion icon does not display the retrieved order records for the selected customer.
How do I get the WebHierarchicalDataGrid to display the customer's related orders when the +expansion icon is clicked?
<ig:WebHierarchicalDataGrid ID="hdg_Customer" runat="server"
Height="600px" Width="95%"
AutoGenerateBands="False" AutoGenerateColumns="False"
DataMember="ods_Customer_DefaultView"
DataSourceID="hds_Customer"
Key="ods_Customer_DefaultView"
DataKeyFields="GUID"
Enabled="False" >
<Bands>
<ig:Band
AutoGenerateColumns="False"
DataMember="ods_Orders_DefaultView"
Key="ods_Orders_DefaultView"
DataKeyFields="GUID" >
<Columns>
<ig:BoundDataField DataFieldName="GUID" Key="GUID">
<Header Text="Order GUID">
</Header>
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="OrderDate" Key="OrderDate">
<Header Text="Order Date">
</Header>
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="TotalOrderAmount" Key="TotalOrderAmount">
<Header Text="Total Order Amount">
</Header>
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="relatedCustomerGUID" Key="relatedCustomerGUID">
<Header Text="related Customer GUID">
</Header>
</ig:BoundDataField>
</Columns>
</ig:Band>
</Bands>
<Columns>
<ig:BoundDataField DataFieldName="GUID" Key="GUID">
<Header Text="Customer GUID">
</Header>
</ig:BoundDataField>--%>
<ig:BoundDataField DataFieldName="CustomerID" Key="CustomerID">
<Header Text="Customer ID">
</Header>
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="CustomerName" Key="CustomerName">
<Header Text="Customer Name">
</Header>
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="CustomerState" Key="CustomerState">
<Header Text="Customer State">
</Header>
</ig:BoundDataField>
</Columns>
</ig:WebHierarchicalDataGrid>
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server"></asp:ScriptManagerProxy>
<ig:WebHierarchicalDataSource ID="hds_Customer" runat="server">
<DataViews>
<ig:DataView ID="ods_Customer_DefaultView"
DataMember="DefaultView"
DataSourceID="ods_Customer" />
<ig:DataView ID="ods_Orders_DefaultView"
DataMember="DefaultView"
DataSourceID="ods_Orders" />
</DataViews>
<DataRelations>
<ig:DataRelation
ChildColumns="relatedCustomerGUID"
ChildDataViewID="ods_Orders_DefaultView"
ParentColumns="GUID"
ParentDataViewID="ods_Customer_DefaultView" />
</DataRelations>
</ig:WebHierarchicalDataSource>
<asp:ObjectDataSource ID="ods_Orders" runat="server"
DataObjectTypeName="Accounts.Order"
OldValuesParameterFormatString="original_{0}"
SelectMethod="LoadAll"
TypeName="Accounts.OrderCollection" >
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ods_Customer" runat="server"
DataObjectTypeName="Accounts.Customer"
OldValuesParameterFormatString="original_{0}"
SelectMethod="LoadAll"
TypeName="Accounts.CustomerCollection" >
</asp:ObjectDataSource>
</asp:Content>
select Customer and related Orders
(tried substituting this):
<asp:ObjectDataSource ID="ods_Orders" runat="server"
DataObjectTypeName="Accounts.Order"
OldValuesParameterFormatString="original_{0}"
SelectMethod="LoadByCustomerGUID"
TypeName="Accounts.OrderCollection" >
<SelectParameters>
<asp:Parameter DefaultValue="" Name="CustomerGUID" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ods_Customer" runat="server"
DataObjectTypeName="Accounts.Customer"
OldValuesParameterFormatString="original_{0}"
SelectMethod="LoadBySequence"
TypeName="Accounts.CustomerCollection" >
<SelectParameters>
<asp:Parameter DefaultValue="0" Name="Sequence" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
Code Behind:
protected void SelectID_Click(object sender, EventArgs e)
{
Accounts.Customer _customer = default(Accounts.Customer);
Accounts.CustomerCollection _customers = default(Accounts.CustomerCollection);
Accounts.OrderCollection _orders = default(Accounts.OrderCollection);
ods_Customer.SelectParameters("CustomerID").DefaultValue = textbox_CustomerID.Text;
_customers = ods_Customer.Select();
_customer = _customers(0);
ods_Orders.SelectMethod = "LoadByCustomerGUID";
ods_Orders.SelectParameters("CustomerGUID").DefaultValue = _customer.GUID.ToString;
_orders = ods_Orders.Select();
}

Check date is Greater using Calendar control in Asp.Net

I'm having a situation where i'm having a Calendar control in my page and when user selects a date it should check whether date selected is greater than today's date.
I tried a lot and Googled it as well, but in every place they are taking value using a textbox and i want the same to be done with a Calendar control.
Contrary to popular belief, you actually don't need any C# code to get this done! All you need is some extenders and validators on your date textbox. So let's say I had two textboxes -- one named txtStartDt and one named txtEndDate; this is how the extensions for them would be placed:
// Start Date
<asp:TextBox ID="txtStartDt" runat="server" CssClass="textboxint" /> // the main control itself
<ajax:CalendarExtender ID="calStartDt" runat="server" PopupPosition="BottomRight"
TargetControlID="txtStartDt" /> // allows the control to behave like a calendar picker
<asp:CompareValidator ID="CVStartDt" runat="server" Type="Date" Operator="LessThan"
ErrorMessage="Start Date must come before the End Date" ValidationGroup="ReportDate"
ControlToValidate="txtStartDt" ControlToCompare="txtEndDt" Display="None" /> // THIS is the main solution to your problem
<ajax:ValidatorCalloutExtender ID="VCEStartDt" runat="server" TargetControlID="CVStartDt"
HighlightCssClass="valCalloutint" /> // Checks that the CV is working correctly
<asp:RequiredFieldValidator ID="RFVStartDt" runat="server" ControlToValidate="txtStartDt"
Display="None" ErrorMessage="Start Date is required" ValidationGroup="ReportDate" /> // ensures a value was added to the textbox
<ajax:ValidatorCalloutExtender ID="VCEreqStartDt" runat="server" TargetControlID="RFVStartDt"
HighlightCssClass="valCalloutint" PopupPosition="BottomRight" /> // Checks that the RFV is working correctly
// End Date
<asp:TextBox ID="txtEndDt" runat="server" CssClass="textboxint" />
<ajax:CalendarExtender ID="calEndDt" runat="server" PopupPosition="BottomRight" TargetControlID="txtEndDt" />
<asp:CompareValidator ID="CVEndDt" runat="server" Type="Date" Operator="GreaterThan"
ErrorMessage="End Date must come after the Start Date" ValidationGroup="ReportDate"
ControlToValidate="txtEndDt" ControlToCompare="txtStartDt" Display="None" />
<ajax:ValidatorCalloutExtender ID="VCEEndDt" runat="server" TargetControlID="CVEndDt"
HighlightCssClass="valCalloutint" />
<asp:RequiredFieldValidator ID="RFVEndDt" runat="server" ControlToValidate="txtEndDt"
Display="None" ErrorMessage="End Date is required" ValidationGroup="ReportDate" />
<ajax:ValidatorCalloutExtender ID="VCEreqEndDt" runat="server" TargetControlID="RFVEndDt"
HighlightCssClass="valCalloutint" PopupPosition="BottomRight" />
Note that the extra ValidatorCalloutExtender tools are not redundant, but actually allows the program to prevent the user from entering an empty value for one of the textboxes.
Hope this helps!!
The calendar control should have a property called SelectedDate. You can compare this property with any other DateTime property. The code snippet below will check if the SelectedDate is greater than today.
if (Calendar.SelectedDate > DateTime.Now())
{
}

How to get the value of selected valueField in Combobox?

I'm trying to assign a value ext:Hidden. I want to set the selected value of the field "HiddenSmo". How to get the value of selected valueField in Combobox?
<DirectEvents>
<Select OnEvent="ValueSelected" After="var ind = #{ComboBoxSmo}.getValue();
#{HiddenSmo}.setValue(#{ComboBoxSmo}.store.getAt(ind).get('code'));" />
</DirectEvents>
but after selection HiddenSmo="". Please help me. thanks in advance. Full code:
<ext:ComboBox
ID="ComboBoxSmo"
runat="server"
DisplayField="name"
ValueField="IdSmo"
TypeAhead="false"
TriggerAction="Query"
QueryMode="Remote"
ForceSelection="true"
SelectOnFocus="true"
Disabled="false"
Name="IDSmo">
<Store>
<ext:Store
runat="server">
<Proxy>
<ext:AjaxProxy
Url="~/Controls/DataService.asmx/GetSMOsD" >
<ActionMethods
Read="POST" />
<Reader>
<ext:XmlReader
Root="ArrayOfSMOResponse"
Record="SMOResponse"
/>
</Reader>
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model
runat="server"
IDProperty="IdSmo">
<Fields>
<ext:ModelField Name="code" Type="Int" />
<ext:ModelField Name="IdSmo" Type="Int" />
<ext:ModelField Name="name" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<DirectEvents>
<Select OnEvent="ValueSelected" After="var ind = #{ComboBoxSmo}.getValue();
#{HiddenSmo}.setValue(#{ComboBoxSmo}.store.getAt(ind).get('code'));" />
</DirectEvents>
Although I don't know the "wrapper language" you use, combo, as any other form fields, has setter and getter of its value:
var val = combo.getValue(); // to get the current combo value
combo.setValue(val); // to set value of the combo to val
try to use this one
App.ComboBoxSmo.getValue()
instead of this #{ComboBoxSmo}.getValue()
I don't understand why you would use a HiddenField to store the value of the combobox selection when the combobox selection already stores it's own value. My guess is that you are trying to workaround what you see as strange behavior within the combobox. So here are some quick pointers I've learned while fighting with combobox's.
If you use a store, you need to shape the object in "setValue([object])" just like the way the store model is shaped.
Use "SelectedItems.Add(...)" and "UpdateSelectedItems()". When just using Ext.Net.ListItems and adding to the Items collection on comboboxes this may not be necessary but when you use a store this seems to be required to get the combobox to play nice with the store on directevents.
<Model>
<ext:Model
runat="server"
IDProperty="IdSmo">
<Fields>
<ext:ModelField Name="code" Type="Int" />
<ext:ModelField Name="IdSmo" Type="Int" />
<ext:ModelField Name="name" Type="String" />
</Fields>
</ext:Model>
</Model>
Server Side:
protected void updateComboBoxSelection(object sender, DirectEventArgs e)
{
if (X.IsAjaxRequest)
{
this.ComboBoxSmo.SelectedItems.Add(new { IdSmo=101, name="foobar", code=15 });
this.ComboBoxDateTime.UpdateSelectedItems();
}
}

Is InsertMethod broken when using ASPxGridView and ObjectDatasource with a custom EditForm?

I have an ASPxGridView, currently 11.1.7.0, which I populate with an ObjectDatasource. Everything works as expected until I use a custom editform. In another control i solved this by using the OnRowInserting attribute in the aspxgridview control, but I dont like this since it's extra work compared to using the objectdatasource.
The code looks something like this.
<dx:ASPxGridView ID="ASPxGridView1" runat="server"
ClientIDMode="AutoID"
AutoGenerateColumns="False"
KeyFieldName="UserId"
DataSourceID="ObjectDataSource1"
ClientInstanceName="grid"
onhtmleditformcreated="AsPxGridView1HtmlEditFormCreated">
<SettingsEditing PopupEditFormWidth="600" PopupEditFormModal="true" Mode="EditForm" />
<Templates>
<TitlePanel>
<dx:ASPxButton ID="New" runat="server" Text="Ny användare" ClientInstanceName="New" AutoPostBack="false">
<ClientSideEvents Click="function (s, e) { grid.AddNewRow(); }" />
</dx:ASPxButton>
</TitlePanel>
<EditForm>
First Name: <dx:ASPxTextBox ID="FirstName" runat="server" />
<dx:ASPxGridViewTemplateReplacement ID="UpdateButton" ReplacementType="EditFormUpdateButton" runat="server" />
<dx:ASPxGridViewTemplateReplacement ID="CancelButton" ReplacementType="EditFormCancelButton" runat="server" />
</EditForm>
</Templates>
<Columns>
<dx:GridViewDataTextColumn FieldName="UserId" VisibleIndex="0" />
<dx:GridViewDataTextColumn FieldName="FirstName" VisibleIndex="2" />
<dx:GridViewDataTextColumn FieldName="LastName" VisibleIndex="3" />
</Columns>
</dx:ASPxGridView>
<asp:ObjectDataSource
ID="ObjectDataSource1"
TypeName="UserData"
SelectMethod="GetItems"
UpdateMethod="ItemUpdate"
InsertMethod="ItemInsert"
DeleteMethod="ItemDelete"
runat="server">
<InsertParameters>
<asp:Parameter Name="FirstName" Type="String"/>
</InsertParameters>
</asp:ObjectDataSource>
And the UserData object
public class UserData
{
public List<TblProUserData> GetItems()
{
var tblProUserData = new TblProUserData();
tblProUserData.Fill();
return tblProUserData.List;
}
public void ItemDelete(int userId)
{ }
public void ItemUpdate()
{ }
public void ItemInsert(string FirstName)
{
// This method gets called, but the FirstName is null.
}
}
The problem is that the ItemInsert gets called, but the FirstName attribute is always null.
Is this a bug? is there a way around this? Did I miss something?
Thanks.
It is necessary to use the Two-Way data-binding technique to bind template editors with DataItem's fields:
<dx:ASPxTextBox ID="FirstName" runat="server" Text='<%#Bind("FirstName")%>' />
Based off the following question, specifying TypeName="UserData" could be causing the problem.
ObjectDataSource not calling Insert method when it has extra parameters
Try removing that from the asp:ObjectDataSource and see if the ItemInsert method works.

Resources