This is a migrated thread and some comments may be shown as answers.

How to retain values in grid ?

1 Answer 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bhanu
Top achievements
Rank 1
Bhanu asked on 07 Aug 2010, 07:32 PM
Hi,

I have a grid with 4 grid bound columns and 1 grid numeric column and the numeric column is in inplace edit mode and there are two buttons - Save & Cancel. When search button clicks, grid will be populated with data.
Here is my requirement.

When user modifies data in the numeric column and clicks on Save button, I have written a validate function to validate the modified data and if the modified data is not as per the rules then those cells should be displayed in red with the modified data so that user can check what was wrong with the data.

Can you please tell me how to achieve this ?

I also have NeedDataSource method & Grid_Prerender method. please see the below code.

protected void Page_Init()
    {
       ConfigureGrid();
                 
    }
  
  
private void ConfigureGrid()
    {
        try
        {
            OrderTypeRankingGrid.AddNeedDataSourceEventHandler(NeedDataSource); 
            OrderTypeRankingGrid.AddGridCommandEventHandler(DataGrid_ItemCommand); 
            OrderTypeRankingGrid.PreRender += new EventHandler(OrderTypeRankingGrid_PreRender);
                                              
             
            OrderTypeRankingGrid.AllowColumnsReorder = false;             
            OrderTypeRankingGrid.GridHeaderText = "Order Type Ranking"
            var masterView = OrderTypeRankingGrid.ConfigureMasterTableView("vDivisionOrderTypeRanking", new string[] { "DivisionOrderTypeRankId","CategoryCode", "PurposeCode", "ReasonCode", "ReasonDescription"});
            masterView.AllowFilteringByColumn = true;
            masterView.AllowSorting = true;
            masterView.FullEditMode = true;
            masterView.EditMode = GridEditMode.InPlace;
            masterView.EnableShowHideColumns = true;
            masterView.SetPaging(GridPagerMode.NextPrevAndNumeric);
            masterView.GridTableView.ShowHeader = true;
            masterView.ShowHeader = true;
            masterView.ShowFooter = true;
            masterView.ShowHeadersWhenNoRecords = true;
            masterView.AllowPaging = true;
            //masterView.PageSize = 50;
              
                          
            masterView.AddNgmCommandButton(NgmButtonType.Save, "btnSave", null, null, null, Unit.Pixel(50));
            masterView.AddNgmCommandButton(NgmButtonType.Cancel, "btnCancel", null, null, null, Unit.Pixel(50));
                          
              
            masterView.CommandItemDisplay = GridCommandItemDisplay.Bottom;
  
              
            if (!IsPostBack)  //must check for postback; otherwise, columns will be duplicated
            {                
                masterView.AddBoundColumn("CategoryCode", "Category Code", "CategoryCode", true, false, true, Unit.Percentage(7.0));
                masterView.AddBoundColumn("PurposeCode", "Purpose Code", "PurposeCode", true, false, true, Unit.Percentage(7.0));
                masterView.AddBoundColumn("ReasonCode", "Reason Code", "ReasonCode", true, false, true, Unit.Percentage(7.0));
                masterView.AddBoundColumn("ReasonDescription", "Reason Description", "ReasonDescription", true, false, true, Unit.Percentage(7.0));
                masterView.AddNumericColumn("OrderTypeRank", "Rank", "OrderTypeRank", false, false, true, Unit.Percentage(7.0), typeof(int),NumericType.Number,"{0:N0}", 10);
                                  
            }            
  
        }
        catch (System.Exception ex)
        {
            base.AddException(ex);
        }               
    }


protected void OrderTypeRankingGrid_PreRender(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            for (int i = 0; i < OrderTypeRankingGrid.PageCount; i++)
            {
                OrderTypeRankingGrid.EditIndexes.Add(i);
            }
  
            OrderTypeRankingGrid.Rebind();
        }
  
  
    }


protected void NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        try
        {
            if (IsPostBack)
            {
                  
                  
               if (!e.IsFromDetailTable && (this.productDivision == 1 || this.productDivision == 2))
                {
                    productDivision = long.Parse(cboxDivision.SelectedValue.ToString());
                    IDivisionOrderTypeRankService divisionOrderTypeRankServiceAgent = null;
                    divisionOrderTypeRankServiceAgent = (IDivisionOrderTypeRankService)ContextRegistry.GetContext().GetObject("DivisionOrderTypeRankServiceAgent");
                    IList<DivisionOrderTypeRankDTO> divisionOrderTypeRankDTOs = divisionOrderTypeRankServiceAgent.GetDivisionOrderTypeRankByDivision(productDivision);
  
                    if (divisionOrderTypeRankDTOs.Count > 1)
                    {
                        var divOrderTypeRankDTOstemp = from b in divisionOrderTypeRankDTOs
                                                       orderby b.CategoryCode ascending, b.PurposeCode ascending, (b.OrderTypeRank == null ? int.MaxValue : b.OrderTypeRank) ascending
                                                       select b;
  
                        OrderTypeRankingGrid.DataSource = divOrderTypeRankDTOstemp;
                                            }
                    else
                    {
                        base.AddWarning("There are no records to display");
   
                    }                    
                }
  
                  
            }
        }
        catch (System.Exception ex)
        {
            base.AddException(ex);
            }
    }

 


1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 11 Aug 2010, 04:15 PM
Hello Bhanu,

You can find suggestions on how to change the invalid control's style on validation at that address. Additionally, you can browse for detailed information about validation on RadGrid updates in this help article.

I hope this helps.

Greetings,
Tsvetina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Bhanu
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or