How to get the value of selected valueField in Combobox? - asp.net

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();
}
}

Related

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();
}

Ext.net 2.0 ComboBox Store

I have a ComboBox Control:
<ext:ComboBox id="comboDatabase"></ext:ComboBox>
In my code I populate the ComboBox Store by:
comboDatabase.Store.Primary.DataSource = dbList
comboDatabase.Store.Primary.DataBind()
However, in my javascript, when I do comboDatabase.getStore().data.items, it returns nothing.
Any idea why? Thanks in advance.
Just define the store:
<ext:ComboBox ID="PACKING" runat="server" FieldLabel="PACKING"
ValueField="id" DisplayField="pk" QueryMode="Local">
<Store>
<ext:Store ID="PackingStore" runat="server" Data='<%# packings %>'>
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="id" />
<ext:ModelField Name="pk" />
</Fields>
</ext:Model>
</Model>
<Reader>
<ext:ArrayReader IDProperty="id" />
</Reader>
</ext:Store>
</Store>
</ext:ComboBox>
c#:
protected object packings
{
get { return ctx.Packings.Select(p => new object[] { p.id, p.PackingName }).ToArray<object>();
}
Is Easy, the same code of ext.net 1.x
EXT.NET CODE
<ext:Store ID="Store1" runat="server" >
<Model>
<ext:Model runat="server" IDProperty="code">
<Fields>
<ext:ModelField Name="code_item" />
<ext:ModelField Name="description_item" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
...
<ext:combobox id="combo" runat="server" storeid="Store1" displayfield="description_item" valuefield="code_item" />
C# CODE
private void LoadStore(Store store, string query)
{
OdbcConnection Odbc = new OdbcConnection();
try
{
Odbc.ConnectionString = mntClass.HelperDB.strConn(); //mntClass is my particular dll
Odbc.Open();
DataSet objDataset1 = new DataSet();
objDataset1 = mntClass.HelperDB.ExecuteSelectQuery(Odbc, query);
store.DataSource = objDataset1;
store.DataBind();
}
catch (OdbcException)
{
}
finally
{
Odbc.Close();
}
}

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

<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

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.

QueryExtender with dropdown list

i am using QueryExtender with dropdownlist to filter gridview ( datasource : EntityDataSource).
<asp:SearchExpression SearchType="StartsWith" DataFields="Status" >
<asp:ControlParameter ControlID="ddlStatus" Type="String" />
</asp:SearchExpression>
Where i bind my ddlStatus from database with default value : "Select"
But when i run project it takes by default value "Select" for Field "status" and gives empty grid.
But on Pageload i want to show all the records after user can select different status from dropdownlist and based on that filter should work.
how can we show all the data with dropdownlist value selected as default "select"
Just Found solution here in book: Entity Framework 4.0 Recipes: A Problem-Solution Approach
Used PropertyExpression instead of SearchExpression
<asp:PropertyExpression>
<asp:ControlParameter ControlID="ddlStatus" Type="String" />
</asp:PropertyExpression>
and leave value blank according to Bala R comment
<asp:ListItem Text="Select" Value="" />
Try using DefaultValue like this
<asp:ListItem Text="Select" Value="Select" />
and
<asp:SearchExpression SearchType="StartsWith" DataFields="Status" >
<asp:ControlParameter ControlID="ddlStatus" Type="String" Default="Select" />
</asp:SearchExpression>

Resources