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

[Solved] Access Insert Item Outside of InsertCommand Event

2 Answers 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Zachary
Top achievements
Rank 1
Zachary asked on 06 May 2013, 03:00 PM
Problem: Need to access values of controls for an insert item outside of RadGrid events. I will not have access to event arguments.

Scenario: User enters values into insert item row client-side, and then selects a grid-external button which will post back to perform complicated business logic. The business logic will access the values entered by the user, and will populate a cell based on entered user values.

Additional Notes: I have no problem performing similar functionality with edit items. I can simply grab RadGrid.EditItems to access the items (rows) I need.

Questions: Is the functionality described above possible? Can I access the values entered into an insert item in the code behind outside of the InsertCommand event?

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 May 2013, 03:46 AM
Hi,

Please check the following code snippet.

C#:
protected void Button1_Click(object sender, EventArgs e)
{
    GridEditFormInsertItem item = (GridEditFormInsertItem)Radgrid1.MasterTableView.GetItems(GridItemType.EditFormItem)[0];
   //accessing a boundcolumn in insert mode
    TextBox txt = (TextBox)item["UniqueName"].Controls[0] ;
}

Thanks,
Princy.
0
Zachary
Top achievements
Rank 1
answered on 07 May 2013, 01:51 PM
Hello Princy,

I was not able to get your solution to work, the length of the returned array was 0. Thank you for your response though.

However, I discovered the GetInsertItem() method, which does resolve my issue. I can't believe I didn't notice it before. An example is show below, please excuse all the hard-coded index values.

Dim strValue As String
strValue =
DirectCast(RadGrid1.MasterTableView.GetInsertItem().cells(6).controls(0),Textbox).Text
Tags
Grid
Asked by
Zachary
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Zachary
Top achievements
Rank 1
Share this question
or