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

Grid ExtractValuesFromItem (newValues, editedItem) returning zero

1 Answer 114 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
K
Top achievements
Rank 1
K asked on 10 Nov 2008, 05:04 PM

One of our developers is experiencing a very odd behavior from RadGrid. The grid is returning zeros for "blank" textbox values when using ExtractValuesFromItem to populate a collection. We need it to return something recognizable (either blank or null) Has anyone seen this and figured out a workaround for it?

We are saving the grid's edited items (from a bulk edit grid) by iterating through the EditItems collection with the following code:

 

 

foreach (GridEditableItem editedItem in RGCounty.EditItems)

 

{

 

Hashtable newValues = new Hashtable();

 

 

//The GridTableView will fill the values from all editable columns in the hash

 

 

 

 

RGCounty.Items[editedItem.ItemIndex].OwnerTableView.ExtractValuesFromItem(newValues, editedItem);

 

//string a=RGCounty.Columns[0].ToString();

 

 

 

 

 

string strUpdateCommand = "Update tblCountyData Set ";

 

 

foreach (string strField in newValues.Keys)

 

{

 

if (strField != strIDField)

 

{

strUpdateCommand = strUpdateCommand + strField +

"= '" + newValues[strField] + "', ";

 

}

}

 

 

//Remove last ,

 

 

 

 

strUpdateCommand = strUpdateCommand.Remove(strUpdateCommand.Length - 2);

strUpdateCommand = strUpdateCommand +

" where id=" + newValues[strIDField];
}

And the ASPX looks like this:

 

 

<asp:SqlDataSource ID="SqlCounty" runat="server"

 

 

ConnectionString="<%$ ConnectionStrings:RdiSds %>"

 

 

onselecting="SqlCounty_Selecting"

 

 

DeleteCommand="DELETE FROM tblCountyData WHERE id = @id"

 

 

 

 

SelectCommand="SELECT [id], [ReportPeriodID], [CountyName], [StateCode], CAST([EstimatedP6Population] AS Varchar) AS EstimatedP6Population, CAST([InTabSample] AS Varchar) AS InTabSample FROM [TblCountyData] WHERE ([ReportPeriodId] = @ReportPeriodId) order by IsNull(statecode, 'ZZ'), IsNull(countyname, 'ZZ')"

 

 

ondeleting="SqlCounty_Deleting">

 

 

 

 

<SelectParameters>

 

 

 

 

<asp:Parameter Name="ReportPeriodID" Type="Int32" />

 

 

 

 

</SelectParameters>

 

 

 

 

<DeleteParameters>

 

 

 

 

<asp:Parameter Name="id" Type="Int32"/>

 

 

 

 

</DeleteParameters>

 

 

 

 

</asp:SqlDataSource>

 

 

 

 

<telerik:RadScriptManager ID="CountyRadScriptManager" runat="server" OutputCompression="AutoDetect"></telerik:RadScriptManager>

 

 

 

 

<br />

 

 

 

 

<asp:Label ID="lblError" runat="server" Text="None" Visible="False" ForeColor="#CC3300"></asp:Label>

 

 

 

 

<input id="EstimatedP6PopulationCheckBoxHid" type="hidden" runat="server" enableviewstate="true"/>

 

 

 

 

<telerik:RadGrid ID="RGCounty" runat="server" DataSourceID="SqlCounty"

 

 

GridLines="None" Skin="Office2007" AllowMultiRowEdit="True"

 

 

AutoGenerateColumns="False" BorderStyle="None" onprerender="RGCounty_PreRender"

 

 

ondatabound="RGCounty_DataBound" onitemdatabound="RGCounty_ItemDataBound" CellSpacing="0" CellPadding="0"

 

 

ondeletecommand="RGCounty_DeleteCommand"><MasterTableView Name="t1" DataKeyNames="id" DataSourceID="SqlCounty" ShowFooter="true">

 

 

 

 

<rowindicatorcolumn>

 

 

 

 

<HeaderStyle Width="20px" />

 

 

 

 

</rowindicatorcolumn>

 

 

 

 

<expandcollapsecolumn>

 

 

 

 

<HeaderStyle Width="20px" />

 

 

 

 

</expandcollapsecolumn>

 

 

 

 

<Columns>

 

 

 

 

<telerik:GridClientDeleteColumn ButtonType="PushButton"

 

 

ConfirmText="Are you sure you want to delete the selected row?"

 

 

HeaderStyle-Width="35px" ShowInEditForm="true" Text="Del" >

 

 

 

 

<HeaderStyle Width="35px" />

 

 

 

 

</telerik:GridClientDeleteColumn>

 

 

 

 

<telerik:GridBoundColumn DataField="id" DataType="System.Int32" HeaderText="id"

 

 

SortExpression="id" UniqueName="id" Visible="False" ForceExtractValue="Always"></telerik:GridBoundColumn>

 

 

 

 

<telerik:GridBoundColumn DataField="ReportPeriodId" DataType="System.Int32"

 

 

HeaderText="ReportPeriodId" UniqueName="ReportPeriodId" Visible="False"></telerik:GridBoundColumn>

 

 

 

 

<telerik:GridTemplateColumn AllowFiltering="False" DataField="CountyName"

 

 

Groupable="False" ShowSortIcon="False" UniqueName="CountyName"><EditItemTemplate><asp:textbox

 

 

ID="CountyNameTextBox" runat="server" ReadOnly="true" Width="150"

 

 

 

 

Text='<%#Bind("CountyName")%>'></asp:textbox><asp:RequiredFieldValidator ID="CountyNameValidator" ControlToValidate="CountyNameTextBox" runat="server"

 

 

 

 

ErrorMessage=" County is Req."></asp:RequiredFieldValidator>

 

 

 

 

</EditItemTemplate>

 

 

 

 

<HeaderTemplate>

 

 

 

 

<asp:CheckBox ID="CountyCheckBox" runat="server" AutoPostBack="true" CausesValidation="false" onClientClick="window.onbeforeunload=null;savePage=true;"

 

 

 

 

EnableViewState="true" oncheckedchanged="CountyCheckBox_CheckedChanged" />

 

 

 

 

&#160;County&#160;Name

 

 

</HeaderTemplate>

 

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

<telerik:GridTemplateColumn AllowFiltering="False" DataField="StateCode"

 

 

Groupable="False" ShowSortIcon="False" UniqueName="StateCode"><EditItemTemplate><asp:textbox

 

 

ID="StateCodeTextBox" runat="server" ReadOnly="true" Width="25" onChange="this.value=this.value.toUpperCase()"

 

 

 

 

Text='<%#Bind("StateCode")%>'></asp:textbox><asp:RegularExpressionValidator ID="StateCodeValidator" ControlToValidate="StateCodeTextBox" ValidationExpression="(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])"

 

 

runat="server" ErrorMessage=" Invalid State Code."></asp:RegularExpressionValidator>

 

 

 

 

</EditItemTemplate>

 

 

 

 

<HeaderTemplate>

 

 

 

 

<asp:CheckBox ID="StateCodeCheckBox" runat="server" AutoPostBack="true" CausesValidation="false" onClientClick="window.onbeforeunload=null;savePage=true;"

 

 

 

 

EnableViewState="true" oncheckedchanged="StateCodeCheckBox_CheckedChanged" />

 

 

 

 

&#160;State&#160;Code

 

 

</HeaderTemplate>

 

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

<telerik:GridTemplateColumn AllowFiltering="False" DataType="System.String"

 

 

 

 

DataField="EstimatedP6Population" Groupable="False" ShowSortIcon="False"

 

 

UniqueName="EstimatedP6Population"><EditItemTemplate><asp:textbox

 

 

ID="EstimatedP6PopulationTextBox" runat="server" ReadOnly="true" Width="100"

 

 

 

 

Text='<%#Bind("EstimatedP6Population")%>'></asp:textbox><asp:RegularExpressionValidator

 

 

 

 

ID="EstimatedP6PopulationValidator" ControlToValidate="EstimatedP6PopulationTextBox" ValidationExpression="\d*" runat="server" ErrorMessage=" Pop. value must be numeric."></asp:RegularExpressionValidator>

 

 

 

 

</EditItemTemplate>

 

 

 

 

<HeaderTemplate>

 

 

 

 

<asp:CheckBox ID="EstimatedP6PopulationCheckBox" runat="server" CausesValidation="false" onClientClick="window.onbeforeunload=null;savePage=true;"

 

 

 

 

AutoPostBack="true" EnableViewState="true"

 

 

oncheckedchanged="EstimatedP6PopulationCheckBox_CheckedChanged" />

 

 

 

 

&#160;Estimated&#160;P6+&#160;Population

 

 

</HeaderTemplate>

 

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

<telerik:GridTemplateColumn AllowFiltering="False" DataType="System.String"

 

 

DataField="InTabSample" Groupable="False" ShowSortIcon="False"

 

 

UniqueName="InTabSample"><EditItemTemplate><asp:textbox

 

 

ID="InTabSampleTextBox" runat="server" Width="100"

 

 

Text='<%#Bind("InTabSample")%>'></asp:textbox><asp:RegularExpressionValidator

 

 

 

 

ID="InTabSampleValidator" ControlToValidate="InTabSampleTextBox" ValidationExpression="\d*" runat="server" ErrorMessage=" In-tab value must be numeric."></asp:RegularExpressionValidator>

 

 

 

 

</EditItemTemplate>

 

 

 

 

<HeaderTemplate>

 

 

 

In-Tab

&nbsp;Sample

 

 

</HeaderTemplate>

 

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

</Columns>

 

 

 

 

</MasterTableView>

 

 

 

 

<clientsettings allowkeyboardnavigation="True">

 

 

 

 

<Selecting AllowRowSelect="True" />

 

 

 

 

<clientevents onkeypress="RGCounty_onkeypress"

 

 

OnGridCreated="onGridCreated_RGCounty" />

 

 

 

 

</clientsettings>

 

 

 

 

<filtermenu enabletheming="True">

 

 

 

 

<collapseanimation duration="200" type="OutQuint" />

 

 

 

 

</filtermenu>

 

 

 

 

</telerik:RadGrid>

 

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 13 Nov 2008, 03:23 PM
Hello,

I tried to reproduce the mentioned issue but unfortunately without avail. Please test the attached sample website and let me know whether it's working as expected.

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Ajax
Asked by
K
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or