Hi,
I posted this query back in April and then May, and received the following replies:
http://www.telerik.com/community/forums/aspnet/general-discussions/how-to-force-a-gridnumericcolumn-on-a-radgrid-to-accept-integer-values-only.aspx
However, these replies still haven't solved the problem.
I have a grid with 3 columns:
Column 1 - a read only GridBoundColumn which displays a string
Column 2 - an editable GridNumericColumn which displays and accepts an integer value only
Column 3 - an editable GridNumericColumn which displays and accepts an double value only
The editable GridNumericColumn (Columns 2 & 3) will always be in edit mode.
The user can then any value on the editable columns.
However, I am still not able to make Column 2 to accept an integer value only (validation done on the client side) .
Column 3 will only accept a double value only.
When the user clicks the submit button on the page, each value of the editable column will be retrieved and stored on the business object.
Can anybody please help me on how to do this (i.e. to make an editable GridNumericColumn on a grid to accept an integer value)?
You can see the web page on http://www.gouw.ws/radgrid
The code is given below:
ASPX
=====
<form id="form1" runat="server">
<div>
<telerik:RadScriptManager ID="radScriptManager" runat="server" />
<telerik:RadGrid ID="radGrid" AutoGenerateColumns="false" AllowMultiRowEdit="true" AllowMultiRowSelection="true" GridLines="Vertical" OnItemCreated="radGrid_ItemCreated" OnPreRender="radGrid_PreRender" OnNeedDataSource="radGrid_NeedDataSource" runat="server">
<ClientSettings>
<Scrolling UseStaticHeaders="true" />
</ClientSettings>
<MasterTableView DataKeyNames="Read" EditMode="InPlace" TableLayout="Fixed">
<Columns>
<telerik:GridBoundColumn DataField="Read" DataType="System.String" HeaderText="Read Only" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" ReadOnly="true" UniqueName="Read" />
<telerik:GridNumericColumn DataField="Integer" DataFormatString="{0:N0}" DataType="System.Int32" HeaderText="Integer Only" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" ReadOnly="false" UniqueName="Integer" />
<telerik:GridNumericColumn DataField="Dbl" DataFormatString="{0:#,##0.#0}" DataType="System.Double" HeaderText="Double Only" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" ReadOnly="false" UniqueName="Dbl" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
</div>
<div align="left">
<asp:Button ID="button" OnClick="button_Click" Text="Submit" runat="server" />
</div>
</form>
ASPX.CS
=======
public partial class Default : System.Web.UI.Page
{
private ArrayList _data = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
this._data = (ArrayList)Session["DATA"];
}
else
{
this._data = Data.Load();
Session["DATA"] = this._data;
}
}
protected void radGrid_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem && e.Item.IsInEditMode)
{
RadNumericTextBox numBox = (e.Item as GridDataItem)["Integer"].Controls[0] as RadNumericTextBox;
numBox.NumberFormat.DecimalDigits = 0;
numBox.NumberFormat.AllowRounding = false;
numBox.NumberFormat.KeepNotRoundedValue = true;
}
}
protected void radGrid_PreRender(object sender, System.EventArgs e)
{
foreach (GridDataItem item in this.radGrid.Items)
{
item.Edit = true;
}
this.radGrid.Rebind();
}
protected void radGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
this.radGrid.DataSource = this._data;
}
protected void button_Click(object sender, EventArgs e)
{
// To fetch the editable value on the grid and to store it into the business object
}
}
Thanks & regards,
Herman Gouw
Skype: hermangouw