Announcement

Collapse
No announcement yet.

ASP.NET DataGrid

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    ASP.NET DataGrid

    Hi there,

    Dunno if any of you guys know much about ASP.NET but I have a slight problem concerning editing data within a datagrid which I would like to pick your brains on.

    I have a datagrid, each row with an edit button. When a row is put into edit mode one of the columns is displayed as a dropdownlist.
    The problem is I cannot seem to set the selected value for this dropdownlist. I have found a couple of guides which suggest I can simply set the selectedIndex property in the HTML like so:

    <EditItemTemplate>
    <asp DropDownList runat="server"
    SelectedIndex='<%# GetStateIndex(Container.DataItem("state")) %>'
    id="edit_State">


    However, in the Visual Studio property box the SelectedIndex property is greyed out
    and when i attempt to run the page I receive the following error message:

    Parser Error Message: The 'SelectedIndex' property is set only by the runtime. It cannot be declared.

    Any ideas on how I can get around this would be very much appreciated.

    cheers,

    #2
    From what I remember, the ItemDataBound event fires when every row of the grid gets initialised. So you need to write a method that handles this event, and there you can initialise the drop down in that row.
    Have a look at these articles:


    Comment


      #3
      I'm not quite sure what you're wanting to do from your description.

      The listindex property is the index of the current item the dropdown list is selected at. It can't be set in the way you're describing above as the combo at that point has no selections in it, so selectindex could never have a value.

      Are you trying to set the values to be their value held in a dataset or other object?

      Comment


        #4
        Yeah that's what I thought Marty, but the guides at 4guysfromrolla and microsoft both say that you can do it that way.

        Anyway, I managed to work out how to do it this morning - sounbds like the same way that kona was suggesting.

        Cheers for the responses guys.

        Comment

        Working...
        X