Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
XML
<dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server"
             KeyFieldName="ProjectID" Width="100%"
            EnableRowsCache="False"  OnRowUpdating="grid_RowUpdating" AutoGenerateColumns="False" OnCellEditorInitialize="grid_CellEditorInitialize">
            <Settings ShowGroupPanel="True" />
            <SettingsEditing Mode="Inline" />
            <Columns>
                <dx:GridViewCommandColumn VisibleIndex="0">
                    <EditButton Visible="true" />
                </dx:GridViewCommandColumn>
                <dx:GridViewDataTextColumn FieldName="ProjectID" ReadOnly="True" VisibleIndex="0"/>

                <dx:GridViewDataColumn FieldName="ProjectName" VisibleIndex="1" />
                <dx:GridViewDataColumn FieldName="ProjectInfo" VisibleIndex="2" />
                <dx:GridViewDataComboBoxColumn   Caption="Project Manager"  FieldName="UserID" VisibleIndex="3">
                   <PropertiesComboBox   TextField="DomainName" ValueField="UserID">
                    </PropertiesComboBox>
                </dx:GridViewDataComboBoxColumn>
            </Columns>
        </dx:ASPxGridView>


I have the aspx file above to display data from joined tables User and Project . User has fields UserID and DomainName and Project has ProjectManagerID(FK on USERID) ProjectInfo and ProjectName
This is how I populate the data

<
C#
    {
        if (!this.IsPostBack)
        {
            //Entity framework query Project.Include("User").ToList();
            grid.DataSource = BUS.Operations.EntityOperations.ProjectOperations.SelectAllProjects();
            grid.DataBind();
        }
    }
    //Upon edit comboboxes are populated
    protected void grid_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
    {
        if (!grid.IsEditing || e.Column.FieldName != "User.DomainName") return;
        if (e.KeyValue == DBNull.Value || e.KeyValue == null) return;
        object val = grid.GetRowValuesByKeyValue(e.KeyValue, "ProjectID");
        if (val == DBNull.Value) return;
        int country = (int)val;
        ASPxComboBox combo = e.Editor as ASPxComboBox;
        FillCityCombo(combo);
        combo.Callback += new CallbackEventHandlerBase(cmbCity_OnCallback);
    }
        protected void FillCityCombo(ASPxComboBox cmb)
        {
            cmb.DataSource= BUS.Operations.EntityOperations.UserOperations.SelectAllProjectManagers();
            cmb.DataBindItems();
        }
and these are callback and rowupdating functions

    void cmbCity_OnCallback(object source, CallbackEventArgsBase e)
    {
        FillCityCombo(source as ASPxComboBox);
    }
    protected void grid_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {

        ASPxGridView gridView = (ASPxGridView)sender;
        int ProjectID = (int)e.Keys[gridView.KeyFieldName];
        P p = new P();
        p.ProjectName = e.NewValues["ProjectName"].ToString();
        p.ProjectInfo = e.NewValues["ProjectInfo"].ToString();
        p.ProjectID = ProjectID;
        //User.DomainName should be inputted as int convertable string
        p.ProjectManagerID = Int32.Parse(((string)e.NewValues["User.DomainName"]));
        BUS.Operations.EntityOperations.ProjectOperations.UpdateProject(p);
        gridView.CancelEdit();
        e.Cancel = true;
    }


Now there are two main problems.

 1.

First and minor one is after selecting another project manager from combobox and click updating I don't see the change in web view although database changed and effect can be seen after page refresh.

 2. Second and major is that If I dont touch combobox and change other fields like project name and click update I get a string on rowupdate method which cannot be converted to int. However if I select from combobox and update an int UserID is coming as I expected.

This is one of my first trials on devexpress and probably this code has lot of mistakes and unnecessary complexity. I need your help for better and working code
Posted
Updated 2-Aug-13 8:56am
v5
Comments
sunpop 27-Nov-13 3:53am    
did u solve it
sunpop 27-Nov-13 3:53am    
if so, could u tell the corrections? Thank you

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