Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is code of aspx page.

ASP.NET
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <dx:ASPxGridView ID="gdStocks"  runat="server" AutoGenerateColumns="False" Width="50%" KeyFieldName="TransId">
        <Columns>
            <dx:GridViewCommandColumn ShowNewButtonInHeader="true" ShowEditButton="true" ShowDeleteButton="true" VisibleIndex="0" ShowClearFilterButton="True" />
            <dx:GridViewDataComboBoxColumn FieldName="StockName" VisibleIndex="1">
                <PropertiesComboBox TextField="StockName" ValueField="StockId" ValueType="System.String" IncrementalFilteringMode="Contains" EnableCallbackMode="true" CallbackPageSize="7"
                    >
                </PropertiesComboBox>
                <EditItemTemplate>
                    <dx:ASPxGridLookup ID="ASPxGridLookup1"  runat="server"
                        AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
                        KeyFieldName="StockId" TextFormatString="{1}"
                        Value='<%# Bind("StockId") %>' IncrementalFilteringMode="Contains">
                        <GridViewProperties>
                            <SettingsBehavior AllowFocusedRow="True" AllowSelectSingleRowOnly="True" />
                        </GridViewProperties>
                        <Columns>
                            <dx:GridViewDataTextColumn FieldName="StockName" VisibleIndex="2">
                            </dx:GridViewDataTextColumn>
                        </Columns>
                    </dx:ASPxGridLookup>
                </EditItemTemplate>
            </dx:GridViewDataComboBoxColumn>
            <dx:GridViewDataDateColumn FieldName="Date" VisibleIndex="2">
            </dx:GridViewDataDateColumn>
            <dx:GridViewDataSpinEditColumn FieldName="Price" VisibleIndex="3">
                <PropertiesSpinEdit DisplayFormatString="g"></PropertiesSpinEdit>
            </dx:GridViewDataSpinEditColumn>
            <dx:GridViewDataTextColumn FieldName="Shares" VisibleIndex="4">
                <EditFormSettings VisibleIndex="4" />
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataComboBoxColumn FieldName="AccountName" VisibleIndex="5">
            </dx:GridViewDataComboBoxColumn>
        </Columns>
        <SettingsEditing EditFormColumnCount="1" Mode="PopupEditForm" PopupEditFormModal="true" />
        <SettingsPopup>
            <EditForm Width="400" />
        </SettingsPopup>
        <SettingsPager Mode="ShowAllRecords" />
        <Settings ShowTitlePanel="true" ShowFilterRow="True" ShowGroupPanel="True" />
        <SettingsText Title="Stock Details" PopupEditFormCaption="Stock Details" />

    </dx:ASPxGridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PortfolioMgt %>"></asp:SqlDataSource>
</asp:Content>

This is code of .cs page

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using conn;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.ASPxEditors;
namespace Final.Test
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        Connection con = new Connection();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["inv_Id"] = 55;
                int invId = (int)Session["inv_Id"];
                fill_gdStocks();
            }
        }
        protected void ASPxComboBox_OnItemsRequestedByFilterCondition_SQL(object source, ListEditItemsRequestedByFilterConditionEventArgs e)
        {
            ASPxComboBox comboBox = (ASPxComboBox)source;
            
            SqlDataSource1.SelectCommand =
            @"SELECT [StockId], [StockName] FROM (select [StockId], [StockName], row_number()over(order by t.[StockName]) as [rn] from [StockMaster] as t where (([StockName]) LIKE @filter)) as st where st.[rn] between @startIndex and @endIndex";
            SqlDataSource1.SelectParameters.Clear();
            SqlDataSource1.SelectParameters.Add("filter", TypeCode.String, string.Format("%{0}%", e.Filter));
            SqlDataSource1.SelectParameters.Add("startIndex", TypeCode.Int64, (e.BeginIndex + 1).ToString());
            SqlDataSource1.SelectParameters.Add("endIndex", TypeCode.Int64, (e.EndIndex + 1).ToString());
            comboBox.DataSource = SqlDataSource1;
            comboBox.DataBind();
        }

        protected void ASPxComboBox_OnItemRequestedByValue_SQL(object source, ListEditItemRequestedByValueEventArgs e)
        {
            long value = 0;
            if (e.Value == null || !Int64.TryParse(e.Value.ToString(), out value))
                return;
            ASPxComboBox comboBox = (ASPxComboBox)source;
            SqlDataSource1.SelectCommand = @"SELECT StockId,StockName FROM StockMaster WHERE (StockId = @StockId) ORDER BY StockName";

            SqlDataSource1.SelectParameters.Clear();
            SqlDataSource1.SelectParameters.Add("StockId", TypeCode.Int64, e.Value.ToString());
            comboBox.DataSource = SqlDataSource1;
            comboBox.DataBind();
        }
        public void fill_gdStocks()
        {
            Session["inv_id"] = 55;
            int invId = (int)Session["inv_id"];
            DataTable dtManage_Stock = new DataTable();
            dtManage_Stock = con.select_ManageStock(invId);
            gdStocks.DataSource = dtManage_Stock;
            gdStocks.DataBind();
        }
    }
}

I get following error when I click on New link in GridView

An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code

Additional information: DataBinding: 'DevExpress.Web.Data.WebCachedDataRow' does not contain a property with the name 'StockId'.
Posted
Updated 12-Mar-15 0:16am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900