locked
Custom GridView Fields RRS feed

  • Question

  • User1991446294 posted

     Hello everyone,

    I have a gridView with AutoGenerateColumns=true and the datasource is a DataTable. I want to insert a column that contains a dropdownlist. 

    The flow will look something like this: Each row from the datagrid has details about some machines (the columns are automatically generated from the datatable). Among these details there is an Image column with elements representing the image that is installed on that machine. When the user edits a row I want to make it possible that he can change the image name, choosing it from a dropdownlist (that has all the images existing in the system). After he chose it i want to show a label with what he chose, instead of the dropdownlist.

    I have 2 issues here: 

    1. The grid has already an image column, which is automatically generated. How can I make that column to be a TemplateField  that has a dropdownlist and label?

    2.  How can I switch between dropdownlist and label?


    Sunday, January 25, 2009 9:56 AM

Answers

  • User1552758296 posted

    Hello,

    You can take two template columns one with dropdown and other with label.

    At the time of display just make the label columns visible and  at the time of edit just make the dropdown visible.

    After editing assign value of selected dropdown to label.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 26, 2009 4:58 AM

All replies

  • User2130758966 posted

     Hey, autogeneratecolumns is usefull for when you dont know what columns are going to be in the grid until run time.

     If you want to customise the layout of your columns and convert it to drop downs as described above then you will want to manually map your own columns then you can click "convert to template" and change the markup to your specific requirements.

     

    This is all outlined in the data access series on this website. I think its in the customising the data modification interface section:

    (ah no, its in the one after that)

    Sunday, January 25, 2009 10:54 AM
  • User1991446294 posted

     Hello,

     Thank you for your quick reply and for the precious link. But it seems that my problem is still unsolved. The issue here is that the datasource for my grid is a DataTable. I need it to be this way because I have access to the DB only through a web service that provides me with data. So I am constructing a datatable out of a list of images and set the datatable as source to the datagrid. So, since I don't have an object or sql data source i don't have access to customization and i am forced to set the autogeneratecolumns to true, or at least this is what i understood.

    So my problem is: 

    Is it possible to create my own columns (with the designer) and then map the data to them from my datatable, without having to set the autogenerate columns to true? And if yes, how can i do it?  

    I know that a solution could be to create a fully customized grid, but i don't want that because I don't have time for it.

    Monday, January 26, 2009 3:27 AM
  • User1552758296 posted

    Hello,

    You can take two template columns one with dropdown and other with label.

    At the time of display just make the label columns visible and  at the time of edit just make the dropdown visible.

    After editing assign value of selected dropdown to label.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 26, 2009 4:58 AM