Adding new row to webgrid in client side code

17 replies. Last post: April 16, 2010 5:27 AM by Handy Surya
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
Darren BuddMember

Hi, I am trying to programmatically add a new row to the grid on client side.  At this point, I dont want to update the data source, just the grid. 

Im using this code to add the row(s), but, the grid just keeps going into limbo with a "Adding new row" message:

 

function AddListItems()

{

// retrieves WebGrid's object var intervalObj; var NewValue = document.getElementById("ctl00_ContentPlaceHolder1_txtNewValues").value; if (NewValue!='')

{

var items = NewValue.split('\r\n'); var grid = ISGetObject("grdlistitemvalue"); if (grid!=null)

{

var i; for (i = 0 ; i < items.length ; i++)

{

if (items[i].trim() != '')

{

alert(
'adding ' + items[i].trim()); var newRow = grid.RootTable.NewRow(); var cells = newRow.GetCells() ; cells.GetNamedItem("itmText").SetText(items[i],true);

newRow.Update();

}

}

}

document.getElementById(
"ctl00_ContentPlaceHolder1_txtNewValues").value = '';

}

else alert('Please enter a value.');

}

 

 

Here is my grid definition:

 

<ISWebGrid:WebGrid ID="grdlistitemvalue" runat="server" DataCacheStorage="Session" Width="100%" UseDefaultStyle="true" Height="500px"> <RootTable RowHeaders="No" DataKeyField="itmID" Caption="List Item Value" AllowAddNew="No"> <Columns> <ISWebGrid:WebGridColumn Name="itmID" Caption="" DataMember="itmID" Visible="false" Width="10px" ShowInSelectColumns="No"> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Name" DataMember="itmText" DataType="System.String" Name="itmText" Width="100px" DefaultFilterType="Contain"> <HeaderStyle CssClass="GridHeaderStyle" /> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Name="Edit" AllowGrouping="No" Caption="Edit" ShowInSelectColumns="No" ButtonAutoPostback="true" ButtonPostbackMode="OnTheFly" Bound="False" Width="35px" ColumnType="ButtonImage" ButtonImage="../../../Images/wg_edit.gif"> <HeaderStyle CssClass="GridHeaderCenterStyle" /> <CellStyle CssClass="GridCellCenterStyle"> </CellStyle> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Name="Delete" DefaultText="Delete" ColumnType="checkbox" Caption="Delete" IsRowChecker="true" Width="200px"> <HeaderStyle CssClass="GridHeaderCenterStyle" /> <CellStyle CssClass="GridCellCenterStyle"> </CellStyle> </ISWebGrid:WebGridColumn> </Columns> </RootTable> <LayoutSettings AlternatingColors="false" AllowColumnMove="Yes" AllowExport="Yes" AllowFilter="Yes" AllowGrouping="Yes" AllowSelectColumns="Yes" AllowSorting="Yes" AlwaysShowHelpButton="False" ApplyFiltersKey="Enter" AutoFilterSuggestion="True" AutoFitColumns="True" GridLineColor="221, 236, 254" GridLines="Horizontal" GroupByBoxVisible="false" Hierarchical="true" RowHighlightType="backgroundonly" ShowRefreshButton="False" TreeLines="false" AutoHeight="false" AutoWidth="false" SizeHeightBy="-7" GridLineStyle="Dotted" InProgressUIBehavior="ChangeCursorToHourGlass"> <HeaderStyle CssClass="GridHeaderWithNoStyle" /> <FocusCellStyle CssClass="GridFocusCellStyle" /> <StatusBarCommandStyle> <Active CssClass="GridStatusBarActiveStyle" BaseStyle="Over"> </Active> <Over CssClass="GridStatusBarOver"> </Over> </StatusBarCommandStyle> <GroupByBox ConnectorLineStyle="None"> <LabelStyle CssClass="GridGroupByBoxLabelStyle" /> <Style CssClass="GridGroupByBoxStyle"></Style> </GroupByBox> <EditTextboxStyle CssClass="GridEditTextboxStyle"> </EditTextboxStyle> <FrameStyle CssClass="GridFrameStyle"> </FrameStyle> <SelectedRowStyle CssClass="GridSelectedRowStyle" /> <%--<AlternatingRowStyle CssClass="GridAltRowStyle" />--%> <StatusBarStyle CssClass="GridStatusBarStyle"> </StatusBarStyle> <RowStyle CssClass="GridRowStyle" /> <EditFocusCellStyle CssClass="GridEditFocusCellStyle"> </EditFocusCellStyle> <GroupRowInfoStyle CssClass="GridGroupRowStyle"> </GroupRowInfoStyle> <ClientSideEvents OnUnhandledError="handleError" OnInitialize="doLoad" OnAfterInitialize="disableExport" /> <ButtonStyle BackColor="Transparent" BorderWidth="0px" Cursor="Hand"> </ButtonStyle> </LayoutSettings> </ISWebGrid:WebGrid>

 

 

can anyone help?

 

thanks

All times are GMT -5. The time now is 11:01 PM.
Previous Next