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

looping through gridview to gather and save data

1 Answer 48 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 27 Nov 2009, 12:07 AM

Hi,

I have a form that uses the rad gridview control. I have 4 text boxes for a user to key in information about a telephone number. Once they click an add button, I place the information into the rad gridview and clear the 4 text boxes. The user then can enter another telephone number and repeat this process as much as necessary.

The data in the rad gridview is not persisted to the database until the user clicks the save button.

When the user clicks the save button, I want to loop through each row in the rad gridview and gather the information and insert it into the database.

How can I accomplish this task? I was trying to use syntax like this:

For Each item In Me.GridTelephone.Items

// gather the 4 values for the telephone for this item

// and insert it into the database

Next

but the .Items collection of the rad gridview is an IList. This means I cannot determine the type of the data in each row such as a string, integer, boolean, and so on.

How can I determine the type of each item as I loop through them. For example:

public class telephone

IsDefault as boolean

Number as string

Country as integer

End Class

dim phone as new Telephone()

For Each item In Me.GridTelephone.Items

// boolean

phone.IsDefault = item ???

// string

phone.Number = item ???

// integer

phone.Country = item ???

Next

So     again, I want to loop through the items and assign the values to a local class which has types.

How can I perform this task?

Bill

1 Answer, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 27 Nov 2009, 06:43 AM
Hi Bill,

You can easily call OfType or Cast for Items property and you will get strongly typed items.

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Bill
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or