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

Retrieve Contents of Textboxes in Add Record Row

2 Answers 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
License
Top achievements
Rank 1
License asked on 14 Oct 2011, 02:20 PM
New to using the Radgrid and trying to learn my way around but I found that I am stuck and need some help.

I have a small web app that allows the user to import a *.csv file that I bind to a RadGrid. I want the user to have the ability to add, edit or delete rows before storing to a table. I've got everything working except adding data.

For the edit (RadGrid.UpdateCommand) I am able to get the Item Index, cast as a GridEditableItem, specify the column name, cast as a textbox and get the text value.

Dim editItem As GridEditableItem = CType(gvMSR.EditItems(e.Item.ItemIndex), GridEditableItem)
dtb.Rows(e.Item.ItemIndex).Item("column1") = CType(editItem("column1").Controls(0), TextBox).Text

When I try to do this for the add record row, which has an Item Index of -1, I get an error "Index was out of range. Must be non-negative and less than the size of the collection."

I have also tried using the unique ID from the sender and concatenating that with the column number to get the unique ID for the individual textbox (which I have verified using Google Chrome dev tools) but get an "Object reference not set to an instance of an object" error.

Dim itemPrefix As String = e.Item.UniqueID.ToString & "$ctl"
dtb.Item("column1") = CType(e.Item.FindControl(itemPrefix & "00"), TextBox).Text

So I'm stuck. I'm sure there is a better way to do this but I'm not familiar enough with RadGrid yet to know how.

Any help is appreciated. Thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 14 Oct 2011, 02:35 PM
Hello,

Dim editItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
Dim txt As TextBox = TryCast(editItem("column1").Controls(0), TextBox)

This code is worked for (both) insert and update.

Let me know if any concern.

Thanks,
Jayesh Goyani
0
License
Top achievements
Rank 1
answered on 14 Oct 2011, 03:26 PM
That works. Thank you.
Tags
Grid
Asked by
License
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
License
Top achievements
Rank 1
Share this question
or