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

Setting RadGrid DefaultInsertValue With TextBox Text

3 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
tony
Top achievements
Rank 1
tony asked on 02 May 2012, 10:38 PM
Is it possible to set the DefaultInsertValue property of a RadGrid with a form control such as TextBox? I have tried the following code without success.

<telerik:GridBoundColumn DataField="ItemID"

FilterControlAltText="Filter column column" HeaderText="Item ID"

 

UniqueName="ItemID" DefaultInsertValue='<% TextBox1.Text %>'>

 

</telerik:GridBoundColumn>


the radgrid control is bound to an entitydatasource  having a two part key one of which is a foreign key needing to be populated with the current entity set's pk.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 May 2012, 10:03 AM
Hello Tony,

One suggestion is you can access the TextBox and set text as shown below.
C#:
protected void RadGrid1_ItemDataBound1(object sender, GridItemEventArgs e)
{
 if (e.Item is GridEditableItem && e.Item.IsInEditMode)
 {
  GridEditableItem item = (GridEditableItem)e.Item;
  TextBox txt = (TextBox)item["ItemID"].Controls[0];
  txt.Text = "some text";
 }
}

Thanks,
Princy.
0
tony
Top achievements
Rank 1
answered on 03 May 2012, 05:01 PM
something like this was my back up plan but i could not reference GridEditableItem. i added some telerick usings but it did not provide the necessary types. what usings/references do i need to resolve GridEditableItem?

i used the OnCommandInsert event but not sure if this is the right place to place the code since i believe that i would need to insert a new row but the grid might also add a row giving me two new rows in the grid when i only need one to set foreign key from the text box outside of the grid.
0
tony
Top achievements
Rank 1
answered on 04 May 2012, 03:43 AM
GridEditableItem is in Telerik.Web.UI not Telerik.Web.UI.Grid as i had assumed. so on with my testing.
Tags
Grid
Asked by
tony
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
tony
Top achievements
Rank 1
Share this question
or