I am very new to dev express .
<dx:ASPxGridView ID="aspxgvOMContracts" runat="server" KeyFieldName="OMContractId" Settings-UseFixedTableLayout="true"
AutoGenerateColumns="False" Settings-HorizontalScrollBarMode="Auto" Width="477px" Theme="PlasticBlue"
OnRowUpdating="aspxgvOMContracts_OnRowUpdating" OnRowUpdated="aspxgvOMContracts_OnRowUpdated">
<SettingsPager PageSize="5" />
<SettingsBehavior AllowFocusedRow="true" />
<SettingsEditing Mode="Inline" />
<%-- <Styles>
<CommandColumnItem Spacing="">
<Paddings PaddingLeft="7" PaddingRight="7" />
</CommandColumnItem>
</Styles>--%>
<Columns>
<dx:GridViewCommandColumn ButtonType="Image" Width="65px" VisibleIndex="0">
<EditButton Visible="True" Image-Url="../Content/Images/icon_edit.png">
</EditButton>
<UpdateButton Visible="True" Image-Url="../Content/Images/icon_update.png">
</UpdateButton>
<CancelButton Visible="true" Image-Url="../Content/Images/icon_cancel.png">
</CancelButton>
<DeleteButton Visible="true" Image-Url="../Content/Images/icon_delete.png">
</DeleteButton>
<ClearFilterButton Visible="True">
</ClearFilterButton>
<%-- <HeaderTemplate>
<dx:ASPxLabel ID="headerLabel" runat="server">
</dx:ASPxLabel>
</HeaderTemplate>--%>
</dx:GridViewCommandColumn>
<dx:GridViewDataComboBoxColumn FieldName="OrganisationName" Caption="OrganisationName" VisibleIndex="1">
<PropertiesComboBox TextField="CompanyName" ValueField="OrganisationId" ValueType="System.Int32">
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
<dx:GridViewDataTimeEditColumn FieldName="DateAnnounced" Caption="DateAnnounced" VisibleIndex="2">
</dx:GridViewDataTimeEditColumn>
<dx:GridViewDataTextColumn FieldName="Cost" Caption="Cost" VisibleIndex="3">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="CostCurrency" Caption="Cost Currency" VisibleIndex="4">
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
and in code behind i Bind the data as
aspxgvOMContracts.DataSource = phase.OMContracts;
aspxgvOMContracts.DataBind();
here phase.OMContracts is of type List()
Now once I edit any row I need the modified collection back . How do I get the modified collection ?
You have assigned the DataSource Property of AspxGridview control then you can directly access that assigned assigned List from DataSource Property, it is a read and write property.
Check the documentation:
ASPxDataWebControlBase.DataSource Property
Gets or sets the object from which the data-bound control retrieves
its list of data items.
From: Get GridView data source to Data table
if you bind gridview on every postback..then you can get DataTable dt = GridView1.DataSource as DataTable;
Same for you alos as List<SomeType> data = grid.DataSource as List<SomeType>;
Hope this help..
Related
I have a multiple Parent-Child Gridview. The problem is Parent gridview Column name is Cost ($) and the ($) symbol is hiding when i expand the Child gridview and get it back when i minimize the Child gridview (Devexpress). The Parent-Child gridview is present in the AspxCallbackPanel and in the PopupControl.
<dx:ASPxCallbackPanel ID="cbpCartDetails" runat="server"
OnCallback="cbpCartDetails_Callback" ClientInstanceName="cbpCartDetails">
<ClientSideEvents EndCallback="cbpCartDetails_EndCallBack" />
<PanelCollection>
<dx:PanelContent ID="pnlCartDetails">
<dx:ASPxPopupControl ClientInstanceName="popCartDetails" Width="600px"
Height="250px" CloseAction="CloseButton" MaxWidth="800px" MaxHeight="800px"
MinHeight="150px" MinWidth="150px" ID="popCartDetails"
HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true"
runat="server" EnableViewState="false" PopupHorizontalAlign="WindowCenter"
PopupVerticalAlign="WindowCenter" EnableHierarchyRecreation="false"
Modal="true">
<ContentCollection>
<dx:PopupControlContentControl ID="PopupControlContentControl2"
runat="server">
<dx:ASPxGridView ID="grdBuildingCartEst" Width="100%"
Theme="SoftOrange" KeyFieldName="CarttypeId"
ClientInstanceName="grdBuildingCartEst">
<Columns>
<dx:GridViewDataTextColumn FieldName="CartType" />
<dx:GridViewDataTextColumn FieldName="NumberOfCart" />
<dx:GridViewDataTextColumn FieldName="Cost" />
</Columns>
<Templates>
<DetailRow>
<dx:ASPxGridView ID="grdFloorsCartEst"
Width="100%"
Theme="SoftOrange"
KeyFieldName="CarttypeId"
OnInit="grdFloorsCartEst_Init"
OnBeforePerformDataSelect=
"grdFloorsCartEst_BeforePerformDataSelect"
ClientInstanceName="grdFloorsCartEst">
<Columns>
<dx:GridViewDataTextColumn
FieldName="CartSize" />
<dx:GridViewDataTextColumn
FieldName="NumberOfCart" />
<dx:GridViewDataTextColumn
FieldName="Cost" />
</Columns>
</dx:ASPxGridView>
</DetailRow>
</Templates>
<SettingsDetail ShowDetailRow="true" />
</dx:ASPxGridView>
</dx:PopupControlContentControl>
</ContentCollection>
</dx:ASPxPopupControl>
</dx:PanelContent>
</PanelCollection>
Screen shot 1
https://i.stack.imgur.com/Fb1QX.png
Screen shot 2 (Error)
https://i.stack.imgur.com/AghdG.png
notice, in the code you've posted, there is no "Cost ($)" string for the master grid column, only FieldName="Cost". Most probably "Cost ($)" is set to column header at codebehind during Page_Load or some other event.
When you expand the child grid there happens a callback and the event code at codebehind where you set Cost ($) is not executed. So, you need to make sure the column header of the master grid is set to "Cost ($)" during child grid expand callback. To be 100% sure, post/attach the codebehind part of your page/control to the question's text.
I am facing a problem for validating the dependency controls. How to validate the another controls which is based on the values of dropdownlist (combo box). Please see the below example. For Example : A dropdown has two values A and B. If user selects "A", then rest of the fields should become required fields and if user selects value “B” from the dropdown, then all other fields should become non-mandatory fields.
Note : i am using the devexpress gridview with default template.
<dx:ASPxGridView ID="ABC" runat="server" AutoGenerateColumns="False"
DataSourceID="ABCDataSource" EnableTheming="True"
Width="100%" ClientInstanceName="gridABC">
<Columns>
<dx:GridViewCommandColumn Caption="Actions" ShowInCustomizationForm="True"
VisibleIndex="0">
<EditButton Visible="True">
</EditButton>
</dx:GridViewCommandColumn>
<dx:GridViewDataComboBoxColumn Caption="List of Type" FieldName="ListType"
ShowInCustomizationForm="True" VisibleIndex="4" Width="100px">
<PropertiesComboBox DataSourceID="ListTypeDataSource"
TextField="ListTypeABC" ValueField="ListTypeABCId" Width="100px">
<ValidationSettings>
<RequiredField ErrorText="ListType required" IsRequired="True" />
</ValidationSettings>
</PropertiesComboBox>
<EditFormSettings ColumnSpan="1" VisibleIndex="1" />
</dx:GridViewDataComboBoxColumn>
<dx:GridViewDataTextColumn Caption="Name" FieldName="Name" ShowInCustomizationForm="True"
VisibleIndex="2" Width="100px">
<PropertiesTextEdit MaxLength="30" Width="100px">
<ValidationSettings>
<RequiredField ErrorText="Item Name required" IsRequired="False" />
</ValidationSettings>
</PropertiesTextEdit>
<EditFormSettings ColumnSpan="1" VisibleIndex="2" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Contact" FieldName="Contact" ShowInCustomizationForm="True"
VisibleIndex="3" Width="100px">
<PropertiesTextEdit MaxLength="30" Width="100px">
<ValidationSettings>
<RequiredField ErrorText="Contact" IsRequired="False" />
</ValidationSettings>
</PropertiesTextEdit>
<EditFormSettings ColumnSpan="1" VisibleIndex="3" />
</dx:GridViewDataTextColumn>
<Templates>
<EditForm>
<table>
<tr>
<td>`<dx:ASPxGridViewTemplateReplacement ReplacementType="EditFormEditors" ID="ASPxGridViewTemplateReplacement1"
runat="server">
</dx:ASPxGridViewTemplateReplacement>
`
The simplest approach is to set the DropDownList's AutoPostBack property to true and handle it's SelectedIndexChanged event. Then you can Enable/Disable the validator there.
Another approach is to use a CustomValidator. This validator is not dependent on a single control. You must write the validation rules on your own. For example the ClientValidationFunction:
<script type="text/javascript" >
function ClientValidate(source, arguments)
{
var txt = document.getElementById('TextBox1');
var ddl = document.getElementById('DropDownList1');
var decision = ddl.options[ddl.selectedIndex].text;
if(decision=='Yes')
{
arguments.IsValid = txt.value.length > 0;
}else{
arguments.IsValid = true;
}
}
</script>
<asp:DropDownList id="DropDownList1" runat="server">
<asp:ListItem Selected="True">Yes</asp:ListItem>
<asp:ListItem Selected="False">No</asp:ListItem>
</asp:DropDownList>
<asp:TextBox id="TextBox1" runat="server" />
<asp:Button ID="BtnSubmit" runat="server" Text="Submit" />
<asp:CustomValidator id="CustomValidator1"
ValidateEmptyText="true"
ControlToValidate="TextBox1"
ClientValidationFunction="ClientValidate"
OnServerValidate="ServerValidation"
Display="Static"
ErrorMessage="Please enter text!"
runat="server"/>
Remember to always implement a OnServerValidate because you should not rely on javascript only(can be disabled). This is easy:
void ServerValidation(object source, ServerValidateEventArgs args)
{
args.IsValid = DropDownList1.SelectedIndex == 1 || TextBox1.Text.Length > 0;
}
I need to show my data in a gridview based on my dropdown list, fromdate and todate when data is entered in the textbox. How can I do that? What I have done till now is I created two pages. In first page I have a dropdown list and a form. When I select value from drop-down list the form for the selected value appears and user can enter details in it and submits that form. After submitting the data store in the database. In second page I have a grid view where stored value can be seen, dropdown list, from date and to date textbox now what I want is to show the records in the gridview based on my dropdown selection, fromdate and todate.
Code for second form:
<asp:DropDownList ID="ddlPortal" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlPortal_SelectedIndexChanged">
<asp:ListItem>TRAVELONG</asp:ListItem>
<asp:ListItem>ONETRAVEL</asp:ListItem>
<asp:ListItem>.UK-BSP</asp:ListItem>
<asp:ListItem>.CA-YYZ</asp:ListItem>
<asp:ListItem>.CA-YVR</asp:ListItem>
<asp:ListItem>Partial MCO Refund</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="lbFrom" Text="From" runat="server" /> <asp:TextBox ID="tbFrom" runat="server" />
<asp:Label ID="lblto" Text="To" runat="server" /> <asp:TextBox ID="tbTo" runat="server" />
<asp:Button ID="btnSearch" runat="server" Text="Search"
onclick="btnSearch_Click" />
Gridview details:
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" onrowcommand="GridView1_RowCommand"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Query">
<itemtemplate>
<asp:LinkButton CommandName="cmdBind" runat="server" Text='<%#Eval("ID")%>' ID="ID" ToolTip='<%#Eval("ID")%>'>LinkButton
</asp:LinkButton>
</itemtemplate>
</asp:TemplateField>
<asp:BoundField DataField="Portal" HeaderText="Portal" />
<asp:BoundField DataField="TID" HeaderText="TID" />
<asp:BoundField DataField="PNR" HeaderText="PNR" />
<asp:BoundField DataField="TicketNumber" HeaderText="Ticket Number" />
<asp:BoundField DataField="ESACCode" HeaderText="ESACCode" />
<asp:BoundField DataField="WaiverCode" HeaderText="WaiverCode" />
<asp:BoundField DataField="Remarks" HeaderText="Remarks" />
<asp:BoundField DataField="UnusedTicketAmount" HeaderText="UnusedTicketAmount" />
<asp:BoundField DataField="ddlUnusedAmount" HeaderText="ddlUnusedAmount" />
<asp:BoundField DataField="AirlinePenality" HeaderText="AirlinePenality" />
<asp:BoundField DataField="ddlAirlinePenality" HeaderText="ddlAirlinePenality" />
<asp:BoundField DataField="NetRefundProcess" HeaderText="NetRefundProcess" />
<asp:BoundField DataField="ddlNetRefundProcess" HeaderText="ddlNetRefundProcess" />
<asp:BoundField DataField="RefundableCommission" HeaderText="RefundableCommission" />
<asp:BoundField DataField="ddlRefundableCommission" HeaderText="ddlRefundableCommission" />
<asp:BoundField DataField="CouponRefunded" HeaderText="CouponRefunded" />
<asp:BoundField DataField="RefundType" HeaderText="RefundType" />
</Columns>
I want to write code on click event of button but I don't know how. Can you help me on this?
.cs file:
protected void btnSearch_Click(object sender, EventArgs e)
{
}
If you are using DataTable for binding your GridView then, you can filter the data & bind your GridView again.
You can use: DataView.RowFilter Property for filtering data.
Eg.:
DataTable dt= GetData();
DataView dv = dt.DefaultView;
dv.RowFilter = "Portal= '" + ddlPortal.SelectedValue.Trim() + "'"
GridView1.DataSource=dv;
GridView1.DataBind();
Also, you can use LINQ to filter data:
DataTable dt= GetData();
EnumerableRowCollection<DataRow> query =
from row in dt.AsEnumerable()
where row.Field<String>("Portal") == ddlPortal.SelectedValue.Trim()
select row;
DataView dv = query.AsDataView();
GridView1.DataSource=dv;
GridView1.DataBind();
I'm trying to load treelist, everything works well but i always see "No Records To Display".
Here is the control:
<telerik:RadTreeList ID="trlProductGroups" runat="server" AllowPaging="true" PageSize="5"
DataKeyNames="ID" ParentDataKeyNames="PARENT_ID" AutoGenerateColumns="false"
OnInsertCommand="trlProductGroups_InsertCommand" OnNeedDataSource="trlProductGroups_NeedDataSource"
OnUpdateCommand="trlProductGroups_UpdateCommand" OnDeleteCommand="trlProductGroups_DeleteCommand">
<Columns>
<telerik:TreeListEditCommandColumn UniqueName="InsertCommandColumn" ButtonType="ImageButton"
HeaderStyle-Width="60px" ItemStyle-HorizontalAlign="Center" />
<telerik:TreeListEditCommandColumn UniqueName="EditCommandColumn" ButtonType="ImageButton">
<ItemStyle CssClass="MyImageButton" />
</telerik:TreeListEditCommandColumn>
<telerik:TreeListButtonColumn UniqueName="DeleteCommandColumn" Text="Delete" CommandName="Delete"
ButtonType="ImageButton" />
<telerik:TreeListBoundColumn DataField="ID" UniqueName="ID" HeaderText="Grup ID"
ReadOnly="true" />
<%-- <telerik:TreeListTemplateColumn DataField="GROUP_NAME" UniqueName="GROUP_NAME" HeaderText="Grup Adı">
<EditItemTemplate>
<asp:TextBox ID="txtGroupName" runat="server"></asp:TextBox>
</EditItemTemplate>
</telerik:TreeListTemplateColumn>--%>
<telerik:TreeListBoundColumn DataField="GROUP_NAME" UniqueName="GROUP_NAME" HeaderText="Grup Adı" />
<telerik:TreeListBoundColumn DataField="PARENT_ID" UniqueName="PARENT_ID" HeaderText="Ana Grup ID"
ReadOnly="true" />
</Columns>
</telerik:RadTreeList>
And here is the NeedDataSource Code:
protected void trlProductGroups_NeedDataSource(object sender, TreeListNeedDataSourceEventArgs e)
{
WebAppTest.Objects.ProductGroups pGroups = new WebAppTest.Objects.ProductGroups();
DataTable dt = pGroups.SelectData(null, string.Empty);
trlProductGroups.DataSource = dt;
}
I can see the data in DataTable, but treelist wont load data. Is there any mistake i make?
Thanks
It's needs to be, at least one data has null id_parent value in datasoruce. Maybe it helps.
I'm using a DevExpress grid and I'm trying to get a 'Country' column to display the header filter properly:
<dx:GridViewDataColumn Caption="Country" FieldName="CountryName"
ShowInCustomizationForm="True" Visible="false">
<Settings AllowHeaderFilter="True"/>
</dx:GridViewDataColumn>
If the 'Country' column is set to Visible='true', then the header filter is displayed as it should(it shows the value option list). However, I want the 'Country' column to be initially hidden, but available in a Customization window(like in the code above). In this case, when the column is dragged outside the Customization window and into the grid and the header filter is clicked, a Javascript error is encountered:
element is null
element.addEventListener(eventName, func, true);
Is this a known bug? Are there any workarounds?
Set the ASPxGridView.Settings.ShowHeaderFilterButton property to true to resolve this problem.
The following markup works fine for me (I am using DXperience 10.1.7):
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/nwind.mdb"
SelectCommand="SELECT * FROM [Categories]"></asp:AccessDataSource>
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" ClientInstanceName="grid"
DataSourceID="AccessDataSource1" KeyFieldName="CategoryID">
<SettingsCustomizationWindow Enabled="True" />
<Columns>
<dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="0">
<EditFormSettings Visible="False"/>
<Settings AllowHeaderFilter="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="CategoryName" Visible="False" VisibleIndex="1">
<Settings AllowHeaderFilter="True" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Description" VisibleIndex="2">
<Settings AllowHeaderFilter="False" />
</dx:GridViewDataTextColumn>
</Columns>
<Settings ShowHeaderFilterButton="True" />
</dx:ASPxGridView>