Joseph Roberts
Top achievements
Rank 1
Joseph Roberts
asked on 02 Aug 2010, 09:12 PM
The following code will show the Insert for when my page loads...
But it does not fire the InitInsert command, which I use to initialize my insert form,with default valus and the like. How can I get the form to display and fire the InitInsert Command, or is there a better way I should be tackling this issue.
Thanks,
Joe
if (!Page.IsPostBack) { Grid.MasterTableView.IsItemInserted = true; Grid.Rebind(); }Thanks,
Joe
4 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 03 Aug 2010, 06:55 AM
Hello Joseph,
If you want to set some default values in TextBoxes when the grid is in insert mode, try the following code snippet in ItemDataBound event.
C#:
Thanks,
Princy.
If you want to set some default values in TextBoxes when the grid is in insert mode, try the following code snippet in ItemDataBound event.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted) // if EditMode is 'EditForms' { GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item; TextBox txt = (TextBox)insertItem["ColumnUniqueName"].Controls[0]; // access the TextBox using ColumnUniqueName txt.Text = "default text";// fill TextBox with some default data } if (e.Item.OwnerTableView.IsItemInserted && e.Item is GridDataInsertItem) // if EditMode is 'InPlace' { GridDataInsertItem insertItem = (GridDataInsertItem)e.Item; TextBox txt = (TextBox)insertItem["ColumnUniqueName"].Controls[0]; txt.Text = "default text"; } }Thanks,
Princy.
0
Joseph Roberts
Top achievements
Rank 1
answered on 03 Aug 2010, 01:21 PM
I guess I was hoping there would be an "easier" way. I currently have my grid setup to do automatic updates and inserts, which works perfectly using the InitInsert command to initialize my form. I understand what you are proposing, and I do beleive it would solve my issue (and I will probably implement it), but I was hoping I could somehow leave my code as is, and somehow simply fire the InitInsert command on my grid on Page_Load.
Is this just not possible?
Thanks,
Joe
Is this just not possible?
Thanks,
Joe
0
Accepted
Princy
Top achievements
Rank 2
answered on 04 Aug 2010, 09:05 AM
Hi,
You can try an alternate method to display insertform and fire the ItemCommand when page loads for first time.
CS:
Thanks,
Princy.
You can try an alternate method to display insertform and fire the ItemCommand when page loads for first time.
CS:
protected void RadGrid1_PreRender(object sender, EventArgs e) { if (!IsPostBack) { GridCommandItem commandItem = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0]; commandItem.FireCommandEvent("InitInsert", null); } } protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) { // Check for the CommandName }Thanks,
Princy.
0
Joseph Roberts
Top achievements
Rank 1
answered on 05 Aug 2010, 04:53 PM
Excactly what I was looking for.
Thank You!
Thank You!