Hi,
The code behind for the code is as follows:
I have a simple grid with an editable column of type string as follows:
<form id="form1" runat="server"> |
<div> |
<telerik:RadScriptManager ID="radScriptManager1" runat="server" /> |
<telerik:RadGrid ID="radGrid1" AutoGenerateColumns="false" GridLines="Vertical" OnItemCreated="radGrid_ItemCreated" OnNeedDataSource="radGrid_NeedDataSource" OnUpdateCommand="radGrid_UpdateCommand" runat="server"> |
<ClientSettings> |
<Scrolling UseStaticHeaders="true" /> |
</ClientSettings> |
<MasterTableView EditMode="InPlace" TableLayout="Fixed"> |
<Columns> |
<telerik:GridBoundColumn DataField="Description" DataType="System.String" HeaderText="Description" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" UniqueName="Description" /> |
<telerik:GridEditCommandColumn ButtonType="LinkButton" UniqueName="Edit" /> |
</Columns> |
</MasterTableView> |
</telerik:RadGrid> |
</div> |
</form> |
I would like to prevent the following characters to be entered by the user into the editable column:
<
>
&
"
'
The code behind for the code is as follows:
public partial class Grid : System.Web.UI.Page |
{ |
private ArrayList _data; |
protected void Page_Load(object sender, EventArgs e) |
{ |
if (!IsPostBack) |
{ |
this._data = Data.Load(); |
Session["DATA"] = this._data; |
} |
else |
{ |
this._data = (ArrayList)Session["DATA"]; |
} |
} |
protected void radGrid_ItemCreated(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
{ |
GridEditableItem item = (GridEditableItem)e.Item; |
TextBox textbox = (TextBox)item["Description"].Controls[0]; |
textbox.Width = Unit.Percentage(99); |
} |
} |
protected void radGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
{ |
this.radGrid.DataSource = this._data; |
} |
protected void radGrid_UpdateCommand(object sender, GridCommandEventArgs e) |
{ |
if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
{ |
GridEditableItem item = (GridEditableItem)e.Item; |
((Data)(this._data[item.ItemIndex])).Description = ((TextBox)item["Description"].Controls[0]).Text; |
Session["DATA"] = this._data; |
} |
} |
} |
public class Data |
{ |
public string Description { get; set; } |
public Data(string description) |
{ |
Description = description; |
} |
public static ArrayList Load() |
{ |
ArrayList arrayList = new ArrayList(); |
arrayList.Add(new Data("Cheeses")); |
arrayList.Add(new Data("Prepared meats")); |
arrayList.Add(new Data("Seaweed and fish")); |
return arrayList; |
} |
} |
Can you please help me how to do this? Do I need to write an event handler for the textbox in radGrid_ItemCreated?
Please show me the code to be inserted above to do this job.
Thanks & regards,
Herman Gouw
Skype: hermangouw