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

making non editable the grid column

2 Answers 51 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sudhakar
Top achievements
Rank 1
Sudhakar asked on 06 Nov 2014, 09:45 AM
Hi Team,

I am using the telerik dll version of 2014.2.724.45

I am facing one issue while editing the grid.

Let me explain the issue.

I have a grid with 5 columns in it and has some data populated. I am implementing batch editing(with batch editing type=cell) for this grid.

When I click on the add new record I am  inserting a new row, here I don't have any issue.
While updating the record I want to make one column non editable, other columns are editable.
How can I achieve this.Please see the aspx and .cs files below

ASPX FILE:

<telerik:RadGrid ID="DischargeRadGrid"   OnItemDataBound="DsichargeRadGridFormat_OnItemDataBound" runat="server" AutoGenerateColumns="false"
                            CssClass="TransferGridPanel" Height="370px" Width="500px" OnItemCommand="DischargeRadGrid_ItemCommand"
                            OnBatchEditCommand="DischargeRadGrid_BatchEditCommand">
                           <MasterTableView ShowHeadersWhenNoRecords="true" CommandItemDisplay="Top" EditMode="Batch" DataKeyNames="Discharge_ID">
                            <CommandItemSettings ShowRefreshButton="false" AddNewRecordText="Add NewDelivery" />
                               <BatchEditingSettings EditType="Cell" />
                                                                 <Columns>
                                    <telerik:GridBoundColumn  UniqueName="DeliveryNo" DataField="Discharge_ID">
                                        <ColumnValidationSettings EnableRequiredFieldValidation="true">
                                            <RequiredFieldValidator ForeColor="Red" Text="*This field is required" Display="Dynamic">                               
                                            </RequiredFieldValidator>
                                        </ColumnValidationSettings>
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  UniqueName="ShipTo"
                                        DataField="Site_ID">
                                        <ColumnValidationSettings EnableRequiredFieldValidation="true">
                                            <RequiredFieldValidator ForeColor="Red" Text="*This field is required" Display="Dynamic">                               
                                            </RequiredFieldValidator>
                                        </ColumnValidationSettings>
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  UniqueName="ShipToName"
                                        DataField="SiteAddress" ReadOnly="true">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  UniqueName="DischargeStart"
                                        DataField="DischargeStartTime" ReadOnly="true">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  UniqueName="DischargeEnd"
                                        DataField="DischargeEndTime">
                                    </telerik:GridBoundColumn>
                                   
                                </Columns>
                            </MasterTableView>
                            <ClientSettings>                           
                           
                            <Scrolling AllowScroll="true"/>
                               
                            </ClientSettings>
                        </telerik:RadGrid>


ASPX.CS FILE


 protected void DischargeRadGrid_BatchEditCommand(object source, GridBatchEditingEventArgs e)
    {
        foreach (GridBatchEditingCommand command in e.Commands)
        {
           
            Hashtable newValues = command.NewValues;
            Hashtable oldValues = command.OldValues;
            string newDischargeId = newValues["Discharge_ID"].ToString();
           
            string newShipTo = newValues["Site_ID"].ToString();
           
            DateTime? dischargeStartTime = DateTime.Now;
            DateTime? dischargeEndTime = DateTime.Now;
            Int32 dropindex;
            Int64 shipmentID = Convert.ToInt64(ShiftTreeView.SelectedNode.Value);
            dropindex = dischargeManager.GetDropIndexCountByDishargeId(shipmentID);
            List<DischargeEntity> dischargeDetails = new List<DischargeEntity>();
            dischargeDetails = dischargeManager.GetDischargeByShipmentId(shipmentID);
            if (command.Type == GridBatchEditingCommandType.Update)
            {
              
                RadWindowManager1.RadConfirm(HTMLEncoder.Encode(MyGlobal.SDP_ALERT_WHILE_UPDATE_LOAD), "confirmCallBackFn", 400, 100, null, null);
              
                var DischargeDal = new DischargeDal();               
                var discharge = new DischargeEntity
                {
                    Discharge_ID = Convert.ToInt64(newDischargeId),
                    Site_ID = Convert.ToInt64(newShipTo),
                    Job_ID = new Guid(),
                    Shipment_ID = shipmentID,
                    Planned = false,                   
                    DropIndex = dropindex,
                    Urgency = dischargeDetails[0].Urgency,
                    DischargeStartTime = dischargeStartTime,
                    DischargeEndTime = dischargeEndTime,                };
                discharge.Discharge_ID = DischargeDal.UpdateDischargeByDischargeId(discharge).Discharge_ID;
                dischargeDetailWsList = new List<DischargeDetailExtraEntity>();
                dischargeDetailWsList = dischargeDetailManager.GetDischargesByShipmentId(Convert.ToInt64(ShiftTreeView.SelectedNode.Value));
                DischargeRadGrid.DataSource = dischargeDetailWsList;
                DischargeRadGrid.DataBind();
            }
            if (command.Type == GridBatchEditingCommandType.Insert)
            {
               
               RadWindowManager1.RadConfirm(HTMLEncoder.Encode(MyGlobal.SDP_ALERT_WHILE_ADD_NEW_LOAD), "confirmCallBackFn", 400, 100, null, null);
               List<DischargeEntity> currentList = (List<DischargeEntity>)Session[_sesDischargeList];              
               DischargeEntity de = currentList[0];
                var DischargeDal = new DischargeDal();              
                if(!(Boolean)de.Planned)
                {
                   
                }
                var discharge = new DischargeEntity
                {
                    Job_ID = new Guid(),
                    Discharge_ID = Convert.ToInt64(newDischargeId),
                    Shipment_ID = shipmentID,
                    DropIndex = dropindex,
                    Site_ID = Convert.ToInt64(newShipTo),
                    Planned = false,
                    PONumber = dischargeDetails[0].PONumber,
                    Urgency = dischargeDetails[0].Urgency,
                    DischargeStartTime = dischargeStartTime,
                    DischargeEndTime=dischargeEndTime,
                };
                discharge.Discharge_ID = DischargeDal.CreateDischarge(discharge).Discharge_ID;
                dischargeDetailWsList = new List<DischargeDetailExtraEntity>();
                dischargeDetailWsList = dischargeDetailManager.GetDischargesByShipmentId(Convert.ToInt64(ShiftTreeView.SelectedNode.Value));
                DischargeRadGrid.DataSource = dischargeDetailWsList;
                DischargeRadGrid.DataBind();            
            }
            if (command.Type == GridBatchEditingCommandType.Delete)
            {
                //perform delete
            }
        }
    }


Please send me the answer asap.it is very urgent.
Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Sudhakar
Top achievements
Rank 1
answered on 07 Nov 2014, 11:51 AM
Hi Team,

Forgot to mention that, while updating the grid I want to make a column noneditable based on some condition.
Like in my scenario I want to make delivery no: column non editable when the planned column(which is not showing in the grid but it is there in the table which is used for populating this grid) value equlas to 1.

Regards,
Sudhakar.
0
Pavlina
Telerik team
answered on 11 Nov 2014, 09:23 AM
Hi Sudhakar,

Please refer to the following forum thread where my colleague Konstantin provided two approaches for disabling column based on another column's value
http://www.telerik.com/forums/telerik-radgrid-using-batch-edit-hide-disable-column-based-on-another-column-s-value

Regards,
Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Sudhakar
Top achievements
Rank 1
Answers by
Sudhakar
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or