There is a page for adding a person to the database (name, address, etc.), there are also 4 types of telephone numbers (work, city, etc.). I need to add several phone numbers of different types (2 mobile, 3 business for example). I want to do this through the GridView component and a sheet. That is, on the add page there is an empty grid without data binding, two columns with combobox and text types, in the combobox phone types (4 pieces). How can I make sure that I fill the table with numbers (using the built-in functions of the grid, creating, saving, etc.) so that when saving numbers they are saved in an empty pre-prepared sheet. I just don’t know exactly how to pull it out of the text field, which is inside the grid, where the number is entered and assign the desired type to it from the combo box and drop the value into a variable in the list.

Component ASPxGridView from DevExpress'a.

    1 answer 1

    It is necessary to work not with the grid itself (which simply displays the data), but with these same data (row models). Suppose in the simplest case, you can use this model:

    public class PhoneNumber { public string Name {get; set;} public string Number {get;set;} } 

    Then, all that the user enters into the appropriate editors will be written into the properties of the model, from where this data can be easily read.

    Since you intend to fill the grid with data yourself and not read them from the database, the ObjectDataSource component will be suitable for binding models to the grid. This component is fully compatible with the grid, and there are several detailed examples in MSDN that demonstrate how to implement methods that will be automatically called to fill the grid with data or to save changes made by the user if the grid is editable.

    In these very methods, you will work only with models, completely abstracting from the grid. So, your code will work equally well as with a grid, and with any other component that supports standard DataSource components in general, and ObjectDataSource in particular.

    In any case, there is no other way, since the grid does not work by itself. Only in conjunction with some DataSource. In principle, anything can be used as a data source, even just a List. But standard ASP.NET components offer more features.