Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
220
WebDataGrid Edit\Add Rows and Disable After RowAdding and Row Updating Events
posted

Hi,

I have an Add , Edit, Update and Cancel Button on top of a WebDataGrid.

Edit should work only for a specific row user clicks first time and after the RowEditing event is fired, the Grid should be made non Editable.

So far I am able to perform the below:

1.) Upon Clicking Add , the RowAdding behavior is enabled . You type something in the added row and only after tab\enter key the row add event is triggered.

2. Upon Clicking Edit, the RowEditing behavior is enabled. You Edit something in a row, you click done and if you click on another row or press enter\tab key, the edit row event is triggered

3. Upon Clicking Cancel, both these behaviors are disabled which is working fine.

4. I have custom logic to ensure either add or edit followed by update and cancel buttons are displayed. When user clicks update I get the value from session and pass it to DAL.

Issues I am facing:

1. In the grdDataTable_RowUpdating event, even though I put rowediting.enabled and editingcore.enabled properties to false still I can edit other rows after the event is fired. What additional properties should I set in this event to ensure the grid is non editable. ?

2. The grdDataTable_RowAdding event, is only triggered when I click enter or tab buttons and not while I click another row. (Please note that the grid reside in a user control(.ascx) which is dynamically populated with data. The WebDataGrid resides in a generic wrapper user control which in turn is used by other user controls.)

3. Given a scenario where user does not click tab, enter or click on another row in the grid(user just types in the values in the add\edit row) and clicks update, is there a way to get the row that was added or edited in Server Side code instead of using the Events? (Seems the row adding\row updating events are only triggered based on a tab or enter key click.)

Behavior Toggling Server Logic:

Method 1->
Public Property editable() As Boolean
        ' --------------------------------------------------------------------------
        ' Property Name:  editable
        ' Description:    Sets/Gets whether the grid is editable 
        ' --------------------------------------------------------------------------
        Get
            Return grdDataTable.Behaviors.EditingCore.Enabled
        End Get
        Set(ByVal Value As Boolean)
            grdDataTable.Behaviors.EditingCore.Enabled = Value
            'grdDataTable.Behaviors.EditingCore.EnableInheritance = Value
        End Set
    End Property

Method 2 Sub Logic->
 With grdDataTable.Behaviors
            Select Case Mode
                Case ModeType.ReadMode
                    .EditingCore.Behaviors.RowAdding.Enabled = False
                    .EditingCore.Behaviors.RowEditing.Enabled = False
                    Me.editable = False
                Case ModeType.AddMode
                    Me.editable = True
                    .EditingCore.Behaviors.RowAdding.Enabled = True
                Case ModeType.EditMode
                    Me.editable = True
                    .EditingCore.Behaviors.RowEditing.Enabled = True
                    grdDataTable.DataKeyFields = Me.DataColumnKey

Events->
    Protected Sub grdDataTable_RowAdding(sender As Object, e As RowAddingEventArgs) Handles grdDataTable.RowAdding
        Session("WebDataGridAddEditRow") = Nothing
        Session.Add("WebDataGridAddEditRow", ConvertHashtableRowsToDataTableColumns(e.Values))
        Me.grdDataTable.Behaviors.EditingCore.Behaviors.RowAdding.Enabled = False
        Me.editable = False
    End Sub

    Protected Sub grdDataTable_RowUpdating(sender As Object, e As RowUpdatingEventArgs) Handles grdDataTable.RowUpdating
        Session("WebDataGridAddEditRow") = Nothing
        Session.Add("WebDataGridAddEditRow", ConvertHashtableRowsToDataTableColumns(e.Values))
        Me.grdDataTable.Behaviors.EditingCore.Behaviors.RowEditing.Enabled = False
        Me.editable = False
    End Sub

WebPage Code:

            <ig:WebDataGrid ID="grdDataTable" runat="server" AutoGenerateColumns="true" width="100%"  ViewStateMode ="Enabled" EnableViewState ="true" EnableAjax="true"
                EnableDataViewState="True"
                HeaderCaptionCssClass="WebDataGridColumnHeader" 
                ItemCssClass = "WebDataGridRow"
                AltItemCssClass = "WebDataGridAlternating"
                OnColumnSorted="grdDataTable_SortColumn"
                OnPageIndexChanged="grdDataTable_PageIndexChanged"
                OnInitializeRow="grdDataTable_InitializeRow" 
                OnRowAdding="grdDataTable_RowAdding"
                OnRowAdded="grdDataTable_RowAdded"
                OnRowUpdating="grdDataTable_RowUpdating">
                <Behaviors>
                    <ig:Selection RowSelectType="Single" CellClickAction="Row" CellSelectType="Single" SelectedRowSelectorCssClass="DataGridSelectedRow" Enabled="true" >
                    </ig:Selection>
                    <ig:Paging PagerAppearance="Bottom" PageSize="100" Enabled="true" />
                    <ig:Sorting SortingMode="Single" Enabled="true" />
                    <ig:ColumnResizing Enabled="false" />
                    <ig:Activation>
                    </ig:Activation>                   
                    <ig:EditingCore Enabled="false" EnableInheritance="false">
                        <Behaviors>
                            <ig:RowAdding Enabled="false" EnableInheritance="false" Alignment="Bottom">
                                <EditModeActions EnableOnActive="true" MouseClick="Single" />  
                             </ig:RowAdding>
                            <ig:RowEditing Enabled="false">                                
                                <EditModeActions EnableOnActive="true" MouseClick="Single" />   
                                <ColumnSettings>
                                                <ig:EditingColumnSetting  ReadOnly="true" />
                                </ColumnSettings>                             
                            </ig:RowEditing>
                          <%--  <ig:Cellediting>
                                    <editmodeactions mouseclick="single" />
                            </ig:Cellediting> --%>                     
                        </Behaviors>
                    </ig:EditingCore>
                </Behaviors>
            </ig:WebDataGrid> 

Thanks,
Aravind

Parents Reply Children
No Data