User Profile & Activity

Shawn August Member
Page
of 19

Hello Shawn,

I did not face the issue in tooltip at all. Would you mind to send me a simple sample of yours? 
FYI, I also tested with your snippet code.

Regards,
Handy

 

Oddly. I can't seem to reproduce in another project. I can't get the tooltip to consistantly be displayed to even see what the tooltip is.

Posted: September 20, 2010 1:08 PM

Hi Shawn,

I am sorry but I am confused with the scenario. I will try to explain it again, using the sample that michael gave, you dont need to set the productID, the grid will fill it as (AUTO) which will be change to the correct data after we accept all the changes. Do you get the same behaviour? or do you got error or unsuccesfull adding the new record?

Best Regards,

Gordon Tumewu

 

Why would it be set to "(AUTO)"?

I see the following code by Michael but don't understand why it is set to "false"?  cells.GetNamedItem("ProductID").SetChanges("false");

 

Here's an example. Please click on the "New Row Causing More Data To Load" button more than once. You will see the exception because the ProductID field isn't set. I don't want to set it nor do I see the need to.
       

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BatchUpdateDeleteRow.aspx.cs" Inherits="BatchUpdateDeleteRow" %>
<%@ Register TagPrefix="iswebgrid" Namespace="ISNet.WebUI.WebGrid" Assembly="ISNet.WebUI.WebGrid" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD runat=server>
		<title>BatchUpdateDeleteRow</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
		<script language="javascript">
		    function WebGrid_SetFieldText(field, text, updateValueField) {
		        try {
		            // Set field's text
		            // NOTE: Default the value to the text if flag is not specified
		            if (field == null) { return; }
		            if (typeof (updateValueField) == "undefined") { updateValueField = true; }
		            field.SetText(text, updateValueField, true);
		        }
		        catch (ex) { ShowJSException(ex); }
		    }

		    function AddNewRowForceNewData() 
		    {
		        var grdInurings = ISGetObject("WebGrid1");
			
		        // Create new row
		        var newRow = grdInurings.RootTable.NewRow();
		        if (newRow == null) { return false; }

		        // Default new row's data
		        // NOTE: Scroll to row before new row to avoid lag from WebGrid loading more data (if exist)
		        grdInurings.ClearSelection();

		        // Address
		        var cells = newRow.GetCells();
		        var address = cells.GetNamedItem("Address");
		        if (address != null) { WebGrid_SetFieldText(address, ""); }

		        // Customer ID
		        var customerID = cells.GetNamedItem("CustomerID");
		        if (customerID != null) 
		        {
		            window.alert("Why does this field need to be set for a new row when the ID is not set until the data is committed?");

		        }
		        newRow.AddPendingChanges();

		        // Focus
		        newRow.Select();
		        
		        return true;
		    }

		    function AddNewRows(numOfNewRows, numOfDeleteRows) 
		    {
		        var grdInurings = ISGetObject("WebGrid1");
		        if (typeof (numOfDeleteRows) == "undefined") { numOfDeleteRows = 0; }		        
		        for (var index = 0; index < numOfNewRows; index++)
		        {
		            var newRow = AddNewRow();
		            if (index < numOfDeleteRows) 
		            {
		                WebGrid_DeleteRow(newRow);
		            }
		        }
		        
		        return true;
		    }

		    function AddNewRow() 
		    {
		        // Create new row
		        var grdInurings = ISGetObject("WebGrid1");
		        var newRow = grdInurings.RootTable.NewRow();
		        if (newRow == null) { return false; }

		        // Default new row's data
		        // NOTE: Scroll to row before new row to avoid lag from WebGrid loading more data (if exist)
		        grdInurings.ClearSelection();

		        // Address
		        var cells = newRow.GetCells();
		        var address = cells.GetNamedItem("Address");
		        if (address != null) { WebGrid_SetFieldText(address, ""); }

		        // Customer ID
		        var customerID = cells.GetNamedItem("CustomerID");
		        if (customerID != null) 
		        {
		            var now = new Date();
		            WebGrid_SetFieldText(customerID, String((now.getSeconds() + now.getMilliseconds())));
		        }
		        newRow.AddPendingChanges();
		        return newRow;
		    }

		    function WebGrid_GetSelectedRow() 
		    {
		        try {
		            // Get selected row
		            var grid = ISGetObject("WebGrid1");
		            if (grid == null) { return; }
		            var selObj = grid.GetSelectedObject();
		            if (selObj == null) { return; }
		            return selObj.ToRowObject();
		        }
		        catch (ex) { ShowJSException(ex); }
		    }

		    function WebGrid_DeleteSelectedRow() 
		    {
		        try {
		            WebGrid_DeleteRow(WebGrid_GetSelectedRow());
		            
		        }
		        catch (ex) { ShowJSException(ex); }
		    }
		    
		    function WebGrid_DeleteRow(row)	
		    {
		        try 
		        {

		            if (row == null) { return; }
		            row.Delete();
		            row.AddPendingChanges();

		            var rowElement = row.GetElement();
		            //if (rowElement != null) { rowElement.style.display = "none"; }
		        }
		        catch (ex) { ShowJSException(ex); }
		    }
		</script>
	</HEAD>
	<body MS_POSITIONING="GridLayout">
		<form id="Form1" method="post" runat="server">
		<input type="button" value="New Row Causing More Data To Load" onclick="javascript:AddNewRowForceNewData();" />
		<input type="button" value="Add 5 new rows and delete 2" onclick="javascript:AddNewRows(5, 2);" />
		<input type="button" value="Delete Selected Row" onclick="javascript:WebGrid_DeleteSelectedRow();" />
		<input type="button" value="Add 10 new rows" onclick="javascript:AddNewRows(10);" />
		<asp:button runat="server" Text="Check WebRowChanges" OnClick="PerformInuringsGridBatchUpdate" />
			<iswebgrid:webgrid id=WebGrid1 runat="server" Height="279px" Width="896px" 
			OnInitializeDataSource="WebGrid1_InitializeDataSource">
                    <LayoutSettings AutoHeight="false" AutoWidth="false" AllowBatchUpdate="true" BatchUpdateSettings-PromptUnsavedChanges="false"
        BatchUpdateSettings-AutomaticObjectUpdate="false" AllowEdit="Yes" EditOnClick="True"
        AllowAddNew="Yes" AllowDelete="Yes" PromptBeforeDelete="true" NewRowLostFocusAction="AlwaysPrompt"
        ResetNewRowValuesOnError="True" RowHeightDefault="22px" AllowFilter="Yes" AllowSelectColumns="Yes"
        AllowSorting="Yes" HideColumnsWhenGrouped="Default" AllowExport="Yes" InProgressUIBehavior="ChangeCursorToHourGlass"
        ApplyFiltersKey="Enter" AllowColumnFreezing="Yes" ShowFilterStatus="True" PagingMode="VirtualLoad"
        VerboseEditingInformation="False" FilterBarVisible="True" PagingExportMode="ExportAllData"
        CellPaddingDefault="0" AlwaysShowHelpButton="False" VirtualPageSize="25">
					<HeaderStyle BorderStyle="Solid" BorderWidth="1px" BackColor="#ECE9D8" ForeColor="Black" Height="20px"
						Font-Size="8pt" Font-Names="Verdana" BorderColor="#ACA899">
						<BorderSettings>
							<Left Color="White"></Left>
							<Top Color="White"></Top>
						</BorderSettings>
					</HeaderStyle>
					<FrameStyle BackColor="#F1EFE2"></FrameStyle>
					<GroupByBox>
						<LabelStyle BorderStyle="Solid" BorderWidth="1px" BackColor="White" Font-Size="8pt" Font-Names="Verdana"
							BorderColor="Navy"></LabelStyle>
						<Style BackColor="Gray">
						</Style>
					</GroupByBox>
					<EditTextboxStyle BorderStyle="None" BorderWidth="0px" Font-Size="8pt" Font-Names="Verdana"></EditTextboxStyle>
					<NewRowStyle BackColor="White" ForeColor="DarkGray" Font-Size="8pt" Font-Names="Verdana"></NewRowStyle>
					<FocusCellStyle BorderStyle="Solid" BorderWidth="1px" BorderColor="Navy"></FocusCellStyle>
					<RowStyle CustomRules="text-overflow: ellipsis; overflow-x: hidden" BackColor="White" Font-Size="8pt"
						Font-Names="Verdana"></RowStyle>
					<GroupRowInfoStyle BorderStyle="Solid" BorderWidth="1px" BackColor="#F1EFE2" Font-Size="8pt" Font-Names="Verdana"
						BorderColor="White">
						<BorderSettings>
							<Bottom Color="Silver"></Bottom>
							<Right Color="Silver"></Right>
						</BorderSettings>
					</GroupRowInfoStyle>
					<SelectedRowStyle BackColor="LightSteelBlue"></SelectedRowStyle>
					<AlternatingRowStyle CustomRules="text-overflow: ellipsis; overflow-x: hidden" BackColor="AntiqueWhite"
						Font-Size="8pt" Font-Names="Verdana"></AlternatingRowStyle>
					<StatusBarStyle BorderStyle="Solid" BorderWidth="1px" BackColor="#ECE9D8" Font-Size="8pt" Font-Names="Verdana"
						BorderColor="#ACA899">
						<Padding Bottom="2px" Left="2px" Top="2px" Right="2px"></Padding>
					</StatusBarStyle>
					<StatusBarCommandStyle>
						<Over BorderWidth="1px" BorderColor="Navy" BorderStyle="Solid" BackColor="CornflowerBlue"></Over>
						<Normal>
							<Padding Bottom="1px" Left="1px" Top="1px" Right="1px"></Padding>
						</Normal>
						<Active BackColor="RoyalBlue" BaseStyle="Over"></Active>
					</StatusBarCommandStyle>
					<PreviewRowStyle ForeColor="#0000C0"></PreviewRowStyle>
				</LayoutSettings>
				<RootTable DataKeyField="CustomerID" Caption="Customers" GridLineStyle="NotSet">
					<Columns>
						<iswebgrid:WebGridColumn Caption="Address" DataMember="Address" Name="Address" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="City" DataMember="City" Name="City" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="CompanyName" DataMember="CompanyName" Name="CompanyName" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="ContactName" DataMember="ContactName" Name="ContactName" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="ContactTitle" DataMember="ContactTitle" Name="ContactTitle" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="Country" DataMember="Country" Name="Country" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="CustomerID" DataMember="CustomerID" Name="CustomerID" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="Fax" DataMember="Fax" Name="Fax" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="Phone" DataMember="Phone" Name="Phone" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="PostalCode" DataMember="PostalCode" Name="PostalCode" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="Region" DataMember="Region" Name="Region" Width="100px"></iswebgrid:WebGridColumn>
					</Columns>
				</RootTable>
			</iswebgrid:webgrid>
			 
		</form>
	</body>
</HTML>

 

Posted: September 20, 2010 1:01 PM

Hello Shawn,

As you have said before that you would get me a sample for this issue.
I think it would be better for me to see the sample first. 
I need to replicate your issue to investigate your issue.

Regards,
Handy

 

I updated an existing page in the WebGrid tutorial to show the two issues I have:

1)  Click on the "Add 5 new rows and delete 2"  button and it will show 5 rows in an Added RowState even though the first two should be deleted. The UI doesn't indicate that any rows are deleted. Highlight an existing row and click "Delete Selected Row". That will change the UI and indicate the RowState as Deleted. This is the same code that deletes rows in the "Add 5 new rows and delete 2" button.

2) Click on the "Add 5 new rows and delete 2"  button and then click the "Check WebRowChanges". This will postback to the server. You will notice all 5 rows are still in an Added state.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BatchUpdateDeleteRow.aspx.cs" Inherits="BatchUpdateDeleteRow" %>
<%@ Register TagPrefix="iswebgrid" Namespace="ISNet.WebUI.WebGrid" Assembly="ISNet.WebUI.WebGrid" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD runat=server>
		<title>BatchUpdateDeleteRow</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
		<script language="javascript">
		    function WebGrid_SetFieldText(field, text, updateValueField) {
		        try {
		            // Set field's text
		            // NOTE: Default the value to the text if flag is not specified
		            if (field == null) { return; }
		            if (typeof (updateValueField) == "undefined") { updateValueField = true; }
		            field.SetText(text, updateValueField, true);
		        }
		        catch (ex) { ShowJSException(ex); }
		    }

		    function AddNewRowForceNewData() 
		    {
		        var grdInurings = ISGetObject("WebGrid1");
			
		        // Create new row
		        var newRow = grdInurings.RootTable.NewRow();
		        if (newRow == null) { return false; }

		        // Default new row's data
		        // NOTE: Scroll to row before new row to avoid lag from WebGrid loading more data (if exist)
		        grdInurings.ClearSelection();

		        // Address
		        var cells = newRow.GetCells();
		        var address = cells.GetNamedItem("Address");
		        if (address != null) { WebGrid_SetFieldText(address, ""); }

		        // Customer ID
		        var customerID = cells.GetNamedItem("CustomerID");
		        if (customerID != null) 
		        {
		            window.alert("Why does this field need to be set for a new row when the ID is not set until the data is committed?");
		            var now = new Date();
		            WebGrid_SetFieldText(customerID, String((now.getSeconds() + now.getMilliseconds())));
		        }
		        newRow.AddPendingChanges();

		        // Focus
		        newRow.Select();
		        
		        return true;
		    }

		    function AddNewRows(numOfNewRows, numOfDeleteRows) 
		    {
		        var grdInurings = ISGetObject("WebGrid1");
		        if (typeof (numOfDeleteRows) == "undefined") { numOfDeleteRows = 0; }		        
		        for (var index = 0; index < numOfNewRows; index++)
		        {
		            var newRow = AddNewRow();
		            if (index < numOfDeleteRows) 
		            {
		                WebGrid_DeleteRow(newRow);
		            }
		        }
		        
		        return true;
		    }

		    function AddNewRow() 
		    {
		        // Create new row
		        var grdInurings = ISGetObject("WebGrid1");
		        var newRow = grdInurings.RootTable.NewRow();
		        if (newRow == null) { return false; }

		        // Default new row's data
		        // NOTE: Scroll to row before new row to avoid lag from WebGrid loading more data (if exist)
		        grdInurings.ClearSelection();

		        // Address
		        var cells = newRow.GetCells();
		        var address = cells.GetNamedItem("Address");
		        if (address != null) { WebGrid_SetFieldText(address, ""); }

		        // Customer ID
		        var customerID = cells.GetNamedItem("CustomerID");
		        if (customerID != null) 
		        {
		            var now = new Date();
		            WebGrid_SetFieldText(customerID, String((now.getSeconds() + now.getMilliseconds())));
		        }
		        newRow.AddPendingChanges();
		        return newRow;
		    }

		    function WebGrid_GetSelectedRow() 
		    {
		        try {
		            // Get selected row
		            var grid = ISGetObject("WebGrid1");
		            if (grid == null) { return; }
		            var selObj = grid.GetSelectedObject();
		            if (selObj == null) { return; }
		            return selObj.ToRowObject();
		        }
		        catch (ex) { ShowJSException(ex); }
		    }

		    function WebGrid_DeleteSelectedRow() 
		    {
		        try {
		            WebGrid_DeleteRow(WebGrid_GetSelectedRow());
		            
		        }
		        catch (ex) { ShowJSException(ex); }
		    }
		    
		    function WebGrid_DeleteRow(row)	
		    {
		        try 
		        {

		            if (row == null) { return; }
		            row.Delete();
		            row.AddPendingChanges();

		            var rowElement = row.GetElement();
		            //if (rowElement != null) { rowElement.style.display = "none"; }
		        }
		        catch (ex) { ShowJSException(ex); }
		    }
		</script>
	</HEAD>
	<body MS_POSITIONING="GridLayout">
		<form id="Form1" method="post" runat="server">
		<input type="button" value="New Row Causing More Data To Load" onclick="javascript:AddNewRowForceNewData();" />
		<input type="button" value="Add 5 new rows and delete 2" onclick="javascript:AddNewRows(5, 2);" />
		<input type="button" value="Delete Selected Row" onclick="javascript:WebGrid_DeleteSelectedRow();" />
		<input type="button" value="Add 10 new rows" onclick="javascript:AddNewRows(10);" />
		<asp:button runat="server" Text="Check WebRowChanges" OnClick="PerformInuringsGridBatchUpdate" />
			<iswebgrid:webgrid id=WebGrid1 runat="server" Height="279px" Width="896px" 
			OnInitializeDataSource="WebGrid1_InitializeDataSource">
                    <LayoutSettings AutoHeight="false" AutoWidth="false" AllowBatchUpdate="true" BatchUpdateSettings-PromptUnsavedChanges="false"
        BatchUpdateSettings-AutomaticObjectUpdate="false" AllowEdit="Yes" EditOnClick="True"
        AllowAddNew="Yes" AllowDelete="Yes" PromptBeforeDelete="true" NewRowLostFocusAction="AlwaysPrompt"
        ResetNewRowValuesOnError="True" RowHeightDefault="22px" AllowFilter="Yes" AllowSelectColumns="Yes"
        AllowSorting="Yes" HideColumnsWhenGrouped="Default" AllowExport="Yes" InProgressUIBehavior="ChangeCursorToHourGlass"
        ApplyFiltersKey="Enter" AllowColumnFreezing="Yes" ShowFilterStatus="True" PagingMode="VirtualLoad"
        VerboseEditingInformation="False" FilterBarVisible="True" PagingExportMode="ExportAllData"
        CellPaddingDefault="0" AlwaysShowHelpButton="False" VirtualPageSize="25">
					<HeaderStyle BorderStyle="Solid" BorderWidth="1px" BackColor="#ECE9D8" ForeColor="Black" Height="20px"
						Font-Size="8pt" Font-Names="Verdana" BorderColor="#ACA899">
						<BorderSettings>
							<Left Color="White"></Left>
							<Top Color="White"></Top>
						</BorderSettings>
					</HeaderStyle>
					<FrameStyle BackColor="#F1EFE2"></FrameStyle>
					<GroupByBox>
						<LabelStyle BorderStyle="Solid" BorderWidth="1px" BackColor="White" Font-Size="8pt" Font-Names="Verdana"
							BorderColor="Navy"></LabelStyle>
						<Style BackColor="Gray">
						</Style>
					</GroupByBox>
					<EditTextboxStyle BorderStyle="None" BorderWidth="0px" Font-Size="8pt" Font-Names="Verdana"></EditTextboxStyle>
					<NewRowStyle BackColor="White" ForeColor="DarkGray" Font-Size="8pt" Font-Names="Verdana"></NewRowStyle>
					<FocusCellStyle BorderStyle="Solid" BorderWidth="1px" BorderColor="Navy"></FocusCellStyle>
					<RowStyle CustomRules="text-overflow: ellipsis; overflow-x: hidden" BackColor="White" Font-Size="8pt"
						Font-Names="Verdana"></RowStyle>
					<GroupRowInfoStyle BorderStyle="Solid" BorderWidth="1px" BackColor="#F1EFE2" Font-Size="8pt" Font-Names="Verdana"
						BorderColor="White">
						<BorderSettings>
							<Bottom Color="Silver"></Bottom>
							<Right Color="Silver"></Right>
						</BorderSettings>
					</GroupRowInfoStyle>
					<SelectedRowStyle BackColor="LightSteelBlue"></SelectedRowStyle>
					<AlternatingRowStyle CustomRules="text-overflow: ellipsis; overflow-x: hidden" BackColor="AntiqueWhite"
						Font-Size="8pt" Font-Names="Verdana"></AlternatingRowStyle>
					<StatusBarStyle BorderStyle="Solid" BorderWidth="1px" BackColor="#ECE9D8" Font-Size="8pt" Font-Names="Verdana"
						BorderColor="#ACA899">
						<Padding Bottom="2px" Left="2px" Top="2px" Right="2px"></Padding>
					</StatusBarStyle>
					<StatusBarCommandStyle>
						<Over BorderWidth="1px" BorderColor="Navy" BorderStyle="Solid" BackColor="CornflowerBlue"></Over>
						<Normal>
							<Padding Bottom="1px" Left="1px" Top="1px" Right="1px"></Padding>
						</Normal>
						<Active BackColor="RoyalBlue" BaseStyle="Over"></Active>
					</StatusBarCommandStyle>
					<PreviewRowStyle ForeColor="#0000C0"></PreviewRowStyle>
				</LayoutSettings>
				<RootTable DataKeyField="CustomerID" Caption="Customers" GridLineStyle="NotSet">
					<Columns>
						<iswebgrid:WebGridColumn Caption="Address" DataMember="Address" Name="Address" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="City" DataMember="City" Name="City" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="CompanyName" DataMember="CompanyName" Name="CompanyName" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="ContactName" DataMember="ContactName" Name="ContactName" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="ContactTitle" DataMember="ContactTitle" Name="ContactTitle" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="Country" DataMember="Country" Name="Country" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="CustomerID" DataMember="CustomerID" Name="CustomerID" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="Fax" DataMember="Fax" Name="Fax" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="Phone" DataMember="Phone" Name="Phone" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="PostalCode" DataMember="PostalCode" Name="PostalCode" Width="100px"></iswebgrid:WebGridColumn>
						<iswebgrid:WebGridColumn Caption="Region" DataMember="Region" Name="Region" Width="100px"></iswebgrid:WebGridColumn>
					</Columns>
				</RootTable>
			</iswebgrid:webgrid>
			 
		</form>
	</body>
</HTML>

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ISNet.WebUI.WebGrid;

public partial class BatchUpdateDeleteRow : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void WebGrid1_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
    {
        dsNorthwind.CustomersDataTable dt = new dsNorthwind.CustomersDataTable();
        dsNorthwindTableAdapters.CustomersTableAdapter da = new dsNorthwindTableAdapters.CustomersTableAdapter();
        da.Fill(dt);
        e.DataSource = dt;
    }

    /// <summary>
    /// Perform batch update on the Inurings WebGrid control's source
    /// </summary>
    /// <param name="source">Source to update</param>
    /// <returns>Updated source after batch update</returns>
    public void PerformInuringsGridBatchUpdate(object sender, EventArgs e)
    {
        // Get changes
        List<WebGridRowChanges> rowChanges = this.WebGrid1.GetChanges();

        // Perform change updates
        foreach (WebGridRowChanges rowChangesItem in rowChanges)
        {
            if (rowChangesItem.KeyValue != null)
            {
                switch (rowChangesItem.RowState)
                {
                    // Add
                    case RowState.Added:

                        break;
                    // Update
                    case RowState.Modified:

                        break;
                    // Delete
                    case RowState.Deleted:
                        break;
                }
            }
        }
    }
}

In my test, the Select function will return error if the row is not in the displayed view. My workaround is to use the GetRowByKeyValue function to check if the newly added row is in the displayed view. If the row is not displayed this function will return null.

Based on your description, I think the scroll into focus script that cause the postback to get more data. Do you mind sharing the code snippet so we could do further testing?

 

Sure.

 

I tried both the New Row's Select() Method and the New Row's 1st editable cell's ActivateEdit() method. It focuses the field and if there is more data available, a postback occurs from the grid.

function AddNewInuring()
    {
        try 
        {
            // Get grid
            var grdInurings = ISGetObject("<%=this.grdInurings.ClientID%>");
            if (grdInurings == null) { return false; }
            
            // Create new row
            var newRow = grdInurings.RootTable.NewRow();
            if (newRow == null) { return false; }
            
            // Default new row's data
            // NOTE: Scroll to row before new row to avoid lag from WebGrid loading more data (if exist)
            grdInurings.ClearSelection();            
            DefaultNewInuringRow(newRow);
            newRow.AddPendingChanges();  
                     
            // Focus
            var treatyName = newRow.GetCells().GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_TREATYNAME%>");
            if (treatyName != null) { treatyName.ActivateEdit(); }
            
            return true;
        }
        catch (ex) { ShowJSException(ex); }       
    }    
    
    function DefaultNewInuringRow(row)
    {
        try
        {                
            if (row == null) { return; }
                                   
            // Selected
            var cells = row.GetCells();
            if (cells == null) { return; }                       
            var selected = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_ISSELECTED%>");
            if (selected != null) { selected.SetValue(false, true); }   
            
            // Treaty Name             
            var treatyName = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_TREATYNAME%>");
            if (treatyName != null) { WebGrid_SetFieldText(treatyName, ""); }
            
            // Portfolio Name List            
            UpdatePortfolioData(row, null);
            
            // Cedant Name
            var cedantName = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_CEDANTNAME%>");
            if (cedantName != null) { WebGrid_SetFieldText(cedantName, ""); }
            
            // Inuring Structure
            var inuringStructure = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_INURINGTYPE_ID%>");
            if (inuringStructure != null) 
            { 
                WebGrid_SetDropDownListValue(inuringStructure, "<%=Endurance.Re.Common.Data.CommonConstants.DROPDOWN_VALUE_SELECT%>", "<%=Endurance.Re.Common.Data.CommonConstants.DROPDOWN_ID_SELECT%>"); 
            }
            
            // Currency Code
            var currencyCode = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_CURRENCYCODE%>");
            if (currencyCode != null) { WebGrid_SetFieldText(currencyCode, "<%=Endurance.Re.AWB.Utility.AWBConstants.INURING_CURRENCYCODE_DEFAULT_VALUE%>"); }
            
            // Occurrency Limit            
            var occurrenceLimit = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_OCCURRENCELIMIT%>");
            if (occurrenceLimit != null) { WebGrid_SetFieldText(occurrenceLimit, "0"); }
            
            // Attachment
            var attachment = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_ATTACHMENT%>");
            if (attachment != null) { WebGrid_SetFieldText(attachment, "0"); }
            
            // Risk Limit
            var riskLimit = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_RISKLIMIT%>");
            if (riskLimit != null) { WebGrid_SetFieldText(riskLimit, "0"); }
             
            // Retention
            var retention = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_RETENTION%>");
            if (retention != null) { WebGrid_SetFieldText(retention, "0"); }
            
            // Placed
            var placed = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_PLACED%>");
            if (placed != null) { WebGrid_SetFieldText(placed, "0"); }
            
            // Covered
            var covered = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_COVERED%>");
            if (covered != null) { WebGrid_SetFieldText(covered, "0"); }
            
            // Effective Date
            var effectiveDate = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_EFFECTIVEDATE%>");
            if (effectiveDate != null) { WebGrid_SetFieldText(effectiveDate, ""); }
            
            // Expiration Date
            var expirationDate = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_EXPIRATIONDATE%>");
            if (expirationDate != null) { WebGrid_SetFieldText(expirationDate, ""); }
            
            // Premium
            var premium = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_PREMIUM%>");
            if (premium != null) { WebGrid_SetFieldText(premium, "0"); }
            
            // Coverage Basis
            var coverageBasis = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_COVERAGEBASISTYPE_ID%>");
            if (coverageBasis != null) 
            { 
                WebGrid_SetDropDownListValue(coverageBasis, "<%=Endurance.Re.Common.Data.CommonConstants.DROPDOWN_VALUE_SELECT%>", "<%=Endurance.Re.Common.Data.CommonConstants.DROPDOWN_ID_SELECT%>"); 
            }
            
            // Attachment Basis
            var attachmentBasis = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_ATTACHMENTBASISTYPE_ID%>");
            if (attachmentBasis != null) 
            { 
                WebGrid_SetDropDownListValue(attachmentBasis, "<%=Endurance.Re.Common.Data.CommonConstants.DROPDOWN_VALUE_SELECT%>", "<%=Endurance.Re.Common.Data.CommonConstants.DROPDOWN_ID_SELECT%>"); 
            }
            
            // Priority
            var priority = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_PRIORITY%>");
            if (priority != null) { WebGrid_SetFieldText(priority, "1"); }
            
            // Number of Reinstatements
            var numReinstatements = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_NUMREINSTATEMENTS%>");
            if (numReinstatements != null) { WebGrid_SetFieldText(numReinstatements, "1"); }
            
            // Reinstatement Charge
            var reinstatementCharge = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_REINSTATEMENTCHARGE%>");
            if (reinstatementCharge != null) { WebGrid_SetFieldText(reinstatementCharge, "0"); }
            
            // Source
            var source = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_SOURCE%>");
            if (source != null) { WebGrid_SetFieldText(source, "<%=Endurance.Re.AWB.Utility.AWBConstants.INURING_SOURCE_USER_DEFAULT_TEXT%>"); } 
            
            // Inuring Notes
            var inuringNotes = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_INURINGNOTES%>");
            if (inuringNotes != null) { WebGrid_SetFieldText(inuringNotes, ""); }
            
            // ID
            // NOTE: This is done to avoid any validation on the DataKeyField being unique
            var id = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_ID%>");
            if (id != null) 
            {
                var now = new Date();
	            WebGrid_SetFieldText(id, (now.getSeconds() + now.getMilliseconds()));
            }
        }
        catch (ex) { ShowJSException(ex); }              
    }        
<CommonCtrl:EnduranceWebGrid runat="server" ID="grdInurings" DefaultStyleMode="Elegant"
                                    UseDefaultStyle="True" Width="100%" Height="100%" ViewStateItems="All" OnInitializeDataSource="grdInurings_OnInitializeDataSource"
                                    OnInitializePostBack="grdInurings_OnInitializePostBack" OnPrepareDataBinding="grdInurings_OnPrepareDataBinding"
                                    OnInitializeLayout="grdInurings_OnInitializeLayout" OnInitializeRow="grdInurings_OnInitializeRow"
                                    OnUpdateRow="grdInurings_OnUpdateRow" OnExport="grdInurings_OnExport">
                                    <LayoutSettings AutoHeight="false" AutoWidth="false" AllowBatchUpdate="true" BatchUpdateSettings-PromptUnsavedChanges="false"
                                        BatchUpdateSettings-AutomaticObjectUpdate="false" AllowEdit="Yes" EditOnClick="True"
                                        AllowAddNew="Yes" AllowDelete="Yes" PromptBeforeDelete="true" NewRowLostFocusAction="AlwaysPrompt"
                                        ResetNewRowValuesOnError="True" RowHeightDefault="22px" AllowFilter="Yes" AllowSelectColumns="Yes"
                                        AllowSorting="Yes" HideColumnsWhenGrouped="Default" AllowExport="Yes" InProgressUIBehavior="ChangeCursorToHourGlass"
                                        ApplyFiltersKey="Enter" AllowColumnFreezing="Yes" ShowFilterStatus="True" PagingMode="VirtualLoad"
                                        VerboseEditingInformation="False" FilterBarVisible="True" PagingExportMode="ExportAllData"
                                        CellPaddingDefault="0" AlwaysShowHelpButton="False" VirtualPageSize="200">
                                        <ClientSideEvents OnInitialize="grdInurings_OnInitialize" OnRowContextMenu="grdInurings_OnRowContextMenu"
                                            OnRowValidate="grdInurings_OnRowValidate" OnRowSelect="grdInurings_OnRowSelect" />
                                        <FrameStyle>
                                            <BorderSettings>
                                                <Top Style="none" />
                                                <Bottom Style="none" />
                                                <Left Color="#6593cf" Width="1" Style="solid" />
                                                <Right Color="#6593cf" Width="1" Style="solid" />
                                            </BorderSettings>
                                        </FrameStyle>
                                        <HeaderStyle CssClass="WebGridHeaderStyle" />
                                        <StatusBarStyle CssClass="WebGridStatusBarStyle" />
                                        <StatusBarCommandStyle Active-CssClass="WebGridStatusBarCommandStyleActive" Normal-CssClass="WebGridStatusBarCommandStyleNormal"
                                            Over-CssClass="WebGridStatusBarCommandStyleOver">
                                            <Normal CssClass="WebGridStatusBarCommandStyleNormal">
                                            </Normal>
                                            <Over CssClass="WebGridStatusBarCommandStyleOver">
                                            </Over>
                                            <Active CssClass="WebGridStatusBarCommandStyleActive">
                                            </Active>
                                        </StatusBarCommandStyle>
                                        <FilterRowStyle CssClass="WebGridFilterRowStyle" />
                                        <PreviewRowStyle CssClass="WebGridRowStyle" />
                                        <RowStyle CssClass="WebGridRowStyle" />
                                        <QuickFilterBarStyle CssClass="WebGridRowStyle" />
                                        <RowHeaderStyle CssClass="WebGridRowHeaderStyle" />
                                        <SelectedRowStyle CssClass="WebGridSelectedRowStyle" />
                                        <EditFocusCellStyle CssClass="WebGridRowStyle" />
                                        <FocusCellStyle CssClass="WebGridRowStyle" />
                                        <LostFocusRowStyle CssClass="WebGridRowStyle" />
                                        <NewRowStyle CssClass="WebGridRowStyle" />
                                        <SortedColumnStyle CssClass="WebGridSortedColumnStyle" />
                                        <AlternatingRowStyle CssClass="WebGridAlternatingRowStyle" />
                                        <EditTextboxStyle CssClass="WebGridEditTextboxStyle" />
                                        <FreezePaneSettings ActiveFrozenColumns="4" ShowInContextMenu="False" ShowSplitterLine="False"
                                            MaxFrozenColumns="4" SplitterLineColor="ActiveBorder" SplitterLineWidth="1" />
                                    </LayoutSettings>
                                    <RootTable Caption="Inurings" DataKeyField="ID" NewRowInfoText="Please click here to create a new Inuring">
                                        <Columns>
                                            <ISWebGrid:WebGridColumn Caption="ID" Name="ID" DataMember="ID" DataType="System.Integer"
                                                ColumnType="Text" EditType="NoEdit" NewRowEditType="NoEdit" FilterEditType="NoEdit"
                                                Width="0px" Visible="false">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="IsReadOnly" Name="IsReadOnly" DataMember="IsReadOnly"
                                                DataType="System.Boolean" ColumnType="Text" EditType="NoEdit" NewRowEditType="NoEdit"
                                                FilterEditType="NoEdit" Width="0px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Select" Name="IsSelected" DataMember="IsSelected"
                                                DataType="System.Boolean" ColumnType="CheckBox" EditType="Checkbox" NewRowEditType="Checkbox"
                                                FilterEditType="Checkbox" Width="40px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Treaty Name" Name="TreatyName" DataMember="TreatyName"
                                                DataType="System.String" ColumnType="Text" EditType="TextBox" NewRowEditType="TextBox"
                                                FilterEditType="TextBox" Width="150px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Portfolio Name" Name="PortfolioNameList" DataMember="PortfolioNameList"
                                                DataType="System.String" ColumnType="Text" EditType="NoEdit" NewRowEditType="NoEdit"
                                                FilterEditType="TextBox" Width="100px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="PortfolioIDList" Name="PortfolioIDList" DataMember="PortfolioIDList"
                                                DataType="System.String" ColumnType="Text" EditType="NoEdit" NewRowEditType="NoEdit"
                                                FilterEditType="NoEdit" Width="0px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Cedant" Name="CedantName" DataMember="CedantName"
                                                DataType="System.String" ColumnType="Text" EditType="TextBox" NewRowEditType="TextBox"
                                                FilterEditType="TextBox" Width="100px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Inuring Structure" Name="InuringTypeID" DataMember="InuringTypeID"
                                                DataType="System.Integer" ColumnType="Custom" EditType="DropdownList" NewRowEditType="DropdownList"
                                                FilterEditType="DropdownList" Width="100px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Currency" Name="CurrencyCode" DataMember="CurrencyCode"
                                                DataType="System.String" ColumnType="Custom" EditType="DropdownList" NewRowEditType="DropdownList"
                                                FilterEditType="DropdownList" Width="70px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Occurrence Limit" Name="OccurrenceLimit" DataMember="OccurrenceLimit"
                                                DataType="System.Integer" ColumnType="Text" EditType="TextBox" NewRowEditType="TextBox"
                                                FilterEditType="TextBox" Width="100px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Attachment" Name="Attachment" DataMember="Attachment"
                                                DataType="System.Integer" ColumnType="Text" EditType="TextBox" NewRowEditType="TextBox"
                                                FilterEditType="TextBox" Width="100px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Risk Limit" Name="RiskLimit" DataMember="RiskLimit"
                                                DataType="System.Integer" ColumnType="Text" EditType="TextBox" NewRowEditType="TextBox"
                                                FilterEditType="TextBox" Width="100px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Retention" Name="Retention" DataMember="Retention"
                                                DataType="System.Integer" ColumnType="Text" EditType="TextBox" NewRowEditType="TextBox"
                                                FilterEditType="TextBox" Width="100px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="%Placed" Name="Placed" DataMember="Placed" DataType="System.Decimal"
                                                ColumnType="Text" EditType="TextBox" NewRowEditType="TextBox" FilterEditType="TextBox"
                                                Width="100px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="%Covered" Name="Covered" DataMember="Covered" DataType="System.Decimal"
                                                ColumnType="Text" EditType="TextBox" NewRowEditType="TextBox" FilterEditType="TextBox"
                                                Width="100px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Effective Date" Name="EffectiveDate" DataMember="EffectiveDate"
                                                DataFormatString="dd-MMM-yyyy" DataType="System.String" ColumnType="Text" EditType="CalendarCombo"
                                                NewRowEditType="CalendarCombo" FilterEditType="CalendarCombo" Width="90px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Expiry Date" Name="ExpirationDate" DataMember="ExpirationDate"
                                                DataFormatString="dd-MMM-yyyy" DataType="System.String" ColumnType="Text" EditType="CalendarCombo"
                                                NewRowEditType="CalendarCombo" FilterEditType="CalendarCombo" Width="90px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Premium" Name="Premium" DataMember="Premium" DataType="System.Integer"
                                                ColumnType="Text" EditType="TextBox" NewRowEditType="TextBox" FilterEditType="TextBox"
                                                Width="100px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Coverage Basis" Name="CoverageBasisTypeID" DataMember="CoverageBasisTypeID"
                                                DataType="System.Integer" ColumnType="Custom" EditType="DropdownList" NewRowEditType="DropdownList"
                                                FilterEditType="DropdownList" Width="100px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Attachment Basis" Name="AttachmentBasisTypeID"
                                                DataMember="AttachmentBasisTypeID" DataType="System.Integer" ColumnType="Custom"
                                                EditType="DropdownList" NewRowEditType="DropdownList" FilterEditType="DropdownList"
                                                Width="100px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Priority" Name="Priority" DataMember="Priority"
                                                DataType="System.DateTime" ColumnType="Text" EditType="TextBox" NewRowEditType="TextBox"
                                                FilterEditType="TextBox" Width="50px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Number of Reinstatements" Name="NumReinstatements"
                                                DataMember="NumReinstatements" DataType="System.DateTime" ColumnType="Text" EditType="TextBox"
                                                NewRowEditType="TextBox" FilterEditType="TextBox" Width="150px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Reinstatement Charge" Name="ReinstatementCharge"
                                                DataMember="ReinstatementCharge" DataType="System.DateTime" ColumnType="Text"
                                                EditType="TextBox" NewRowEditType="TextBox" FilterEditType="TextBox" Width="125px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Source" Name="Source" DataMember="Source" DataType="System.String"
                                                ColumnType="Text" EditType="NoEdit" NewRowEditType="NoEdit" FilterEditType="TextBox"
                                                Width="50px">
                                            </ISWebGrid:WebGridColumn>
                                            <ISWebGrid:WebGridColumn Caption="Notes" Name="InuringNotes" DataMember="InuringNotes"
                                                DataType="System.String" ColumnType="Text" EditType="TextBox" NewRowEditType="TextBox"
                                                FilterEditType="TextBox" Width="300px">
                                            </ISWebGrid:WebGridColumn>
                                        </Columns>
                                    </RootTable>
                                </CommonCtrl:EnduranceWebGrid>

 

Posted: September 17, 2010 11:15 AM

After calling the Row's Delete() method, the Row's GetRowState() method still indicates the row is 'Added'. Shouldn't it be 'Delete'? How can I tell which rows have been deleted or marked for deleted?

 

This is a problem. A row that was created and then deleted still has a "GetRowState()" as "Added". After the postback, the WebRowChanges only has "Added" and not "Deleted" so the row is NEVER deleted.


If I just DELETE an existing row, the WebRowChanges has the delete and it works as expected.

 

Fantastic! This allowed me to update the field regardless if the EditType was set to NoEdit.


However, the textbox's tooltip still has the previous data.

 

For example,

Cell.SetText("Hello World", true, true) = "Hello World" and tooltip of "Hello World"

Cell.SetText("", true, true) = "" and tooltip of "Hello World"

 

Can you confirm?

Posted: September 16, 2010 11:30 PM

Normally, in batch update mode, when you called Delete() or delete manually by pressing 'delete' key in keyboard, the current row would be marked.
As you can see in my video, there should delete icon indicator and would be added as pending changes.
So, that's why I am confused why you insist to say that you could not see the indicator.
Suggest a workaround to hide the row when use delete() also would not help much.
Even though you hide the row, it is still added in pending changes.
It would not go away from pending changes, except you have clicked accept or cancel the pending changes.

Regards,
Handy

 

I am not sure why the delete icon indicator isn't working for me either? The add icon indicator still appears. 


Hiding the row is exactly what I want. The user deleted the row and doesn't want to see it anymore. I added the suggested code to HIDE it. After the page is submitted, I will be able to delete the row as it will be in the WebRowChanges collection.

 

Hello Shawn,

Do you mean for each cell? Because we don't have EditType for row. We only have EditType for WebGrid Column in cell level.
You should not be able to do at row level. Besides, Row object does not have SetText() method.

In order to do this in No Edit type, you can use SetText(). Please see the code below.

function Button1_onclick() {
            var grid = ISGetObject("WebGrid1");
            grid.GetSelectedObject().ToRowObject().GetCells()[1].SetText("Hello World", true,true);
           
        }

The last parameter is ignore edit type parameter. You can return true or false.

Regards,
Handy

 

 

My apologies as I meant Cell when I typed Row. The last parameter sounds exactly like I need! It is not listed in the documentation anywhere so I was not aware it existed. Is there any other parameters?

 

I will test in the morning.

Posted: September 16, 2010 11:24 PM

Hi,

As I said earlier, WebGrid still need the DataKeyField to make the scenario worked. Actually you just need to set it to your primary key and the problem should be solved.

Best Regards,

Gordon Tumewu

 

You are not understanding the problem.

 

I understand the DataKeyField needs to be set.  The problem is that the DataKeyField needs a value for each row or the exception message that has been discussed above is displayed.  The only way around that is to specify a value for the DataKeyField.  This is poor design because this data will not be available until the data is committed to the database.  How do you get around NOT having to set this data for newly created fields?

I'd like to ask you a favor by providing the function that will be fired when user add row(s) to the grid with default data (by clicking the button).

Observing the function will helps to determine why does the OnRowValidate client-side event not fired.

 

Sure.

 

function wtbPageToolbar_OnClick() 
    {
        try 
        {
            // Create Inuring
            AddNewInuring();
        }
        catch (ex) { ShowJSException(ex); }
    }

    function AddNewInuring()
    {
        try 
        {
            // Get grid
            var grdInurings = ISGetObject("<%=this.grdInurings.ClientID%>");
            if (grdInurings == null) { return false; }
            
            // Create new row
            var newRow = grdInurings.RootTable.NewRow();
            if (newRow == null) { return false; }
            
            // Default new row's data
            grdInurings.ClearSelection();            
            DefaultNewInuringRow(newRow);
            newRow.AddPendingChanges();
            
            return true;
        }
        catch (ex) { ShowJSException(ex); }       
    }    
    
    function DefaultNewInuringRow(row)
    {
        try
        {                
            if (row == null) { return; }
                                   
            // Selected
            var cells = row.GetCells();
            if (cells == null) { return; }                       
            var selected = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_ISSELECTED%>");
            if (selected != null) { selected.SetValue(false, true); }   
            
            // Treaty Name             
            var treatyName = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_TREATYNAME%>");
            if (treatyName != null) { WebGrid_SetFieldText(treatyName, ""); }
            
            // Portfolio Name List            
            UpdatePortfolioData(row, null);
            
            // Cedant Name
            var cedantName = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_CEDANTNAME%>");
            if (cedantName != null) { WebGrid_SetFieldText(cedantName, ""); }
            
            // Inuring Structure
            var inuringStructure = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_INURINGTYPE_ID%>");
            if (inuringStructure != null) 
            { 
                WebGrid_SetDropDownListValue(inuringStructure, "<%=Endurance.Re.Common.Data.CommonConstants.DROPDOWN_VALUE_SELECT%>", "<%=Endurance.Re.Common.Data.CommonConstants.DROPDOWN_ID_SELECT%>"); 
            }
            
            // Currency Code
            var currencyCode = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_CURRENCYCODE%>");
            if (currencyCode != null) { WebGrid_SetFieldText(currencyCode, "<%=Endurance.Re.AWB.Utility.AWBConstants.INURING_CURRENCYCODE_DEFAULT_VALUE%>"); }
            
            // Occurrency Limit            
            var occurrenceLimit = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_OCCURRENCELIMIT%>");
            if (occurrenceLimit != null) { WebGrid_SetFieldText(occurrenceLimit, "0"); }
            
            // Attachment
            var attachment = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_ATTACHMENT%>");
            if (attachment != null) { WebGrid_SetFieldText(attachment, "0"); }
            
            // Risk Limit
            var riskLimit = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_RISKLIMIT%>");
            if (riskLimit != null) { WebGrid_SetFieldText(riskLimit, "0"); }
             
            // Retention
            var retention = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_RETENTION%>");
            if (retention != null) { WebGrid_SetFieldText(retention, "0"); }
            
            // Placed
            var placed = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_PLACED%>");
            if (placed != null) { WebGrid_SetFieldText(placed, "0"); }
            
            // Covered
            var covered = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_COVERED%>");
            if (covered != null) { WebGrid_SetFieldText(covered, "0"); }
            
            // Effective Date
            var effectiveDate = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_EFFECTIVEDATE%>");
            if (effectiveDate != null) { WebGrid_SetFieldText(effectiveDate, ""); }
            
            // Expiration Date
            var expirationDate = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_EXPIRATIONDATE%>");
            if (expirationDate != null) { WebGrid_SetFieldText(expirationDate, ""); }
            
            // Premium
            var premium = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_PREMIUM%>");
            if (premium != null) { WebGrid_SetFieldText(premium, "0"); }
            
            // Coverage Basis
            var coverageBasis = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_COVERAGEBASISTYPE_ID%>");
            if (coverageBasis != null) 
            { 
                WebGrid_SetDropDownListValue(coverageBasis, "<%=Endurance.Re.Common.Data.CommonConstants.DROPDOWN_VALUE_SELECT%>", "<%=Endurance.Re.Common.Data.CommonConstants.DROPDOWN_ID_SELECT%>"); 
            }
            
            // Attachment Basis
            var attachmentBasis = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_ATTACHMENTBASISTYPE_ID%>");
            if (attachmentBasis != null) 
            { 
                WebGrid_SetDropDownListValue(attachmentBasis, "<%=Endurance.Re.Common.Data.CommonConstants.DROPDOWN_VALUE_SELECT%>", "<%=Endurance.Re.Common.Data.CommonConstants.DROPDOWN_ID_SELECT%>"); 
            }
            
            // Priority
            var priority = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_PRIORITY%>");
            if (priority != null) { WebGrid_SetFieldText(priority, "1"); }
            
            // Number of Reinstatements
            var numReinstatements = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_NUMREINSTATEMENTS%>");
            if (numReinstatements != null) { WebGrid_SetFieldText(numReinstatements, "1"); }
            
            // Reinstatement Charge
            var reinstatementCharge = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_REINSTATEMENTCHARGE%>");
            if (reinstatementCharge != null) { WebGrid_SetFieldText(reinstatementCharge, "0"); }
            
            // Source
            var source = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_SOURCE%>");
            if (source != null) { WebGrid_SetFieldText(source, "<%=Endurance.Re.AWB.Utility.AWBConstants.INURING_SOURCE_USER_DEFAULT_TEXT%>"); } 
            
            // Inuring Notes
            var inuringNotes = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_INURINGNOTES%>");
            if (inuringNotes != null) { WebGrid_SetFieldText(inuringNotes, ""); }
            
            // ID
            // NOTE: This is done to avoid any validation on the DataKeyField being unique
            var id = cells.GetNamedItem("<%=Endurance.Re.AWB.Utility.AWBConstants.SP_COL_INURING_GET_ID%>");
            if (id != null) 
            {
                var now = new Date();
	            WebGrid_SetFieldText(id, (now.getSeconds() + now.getMilliseconds()));
            }
        }
        catch (ex) { ShowJSException(ex); }              
    }        

function WebGrid_SetFieldText(field, text, updateValueField) 
{
    try 
    {
        // Set field's text
        // NOTE: Default the value to the text if not specified
        if (field == null) { return; }
        if (typeof (updateValueField) == "undefined") { updateValueField = true; }
        //var forceNoEdit = field.ForceNoEdit;
        //field.SetForceNoEdit(false);
        field.SetText(text, updateValueField);
        //field.SetForceNoEdit(forceNoEdit);        
    }
    catch (ex) { ShowJSException(ex); }
}
All times are GMT -5. The time now is 2:04 PM.
Previous Next