DataGrid with edititemtemplate

Discussion in 'ASP .Net Web Controls' started by Guest, Jun 13, 2005.

  1. Guest

    Guest Guest

    Hi
    I have a datagrid defined which I would like to make it editable. So I put
    in some editcommand and BoundColumn and template column with item template.
    I don't have problem in setting a column to textbox in edititemtemplate, but
    how do I set it to dropdownlist and how do I set the selectedIndex?

    TIA

    --
    Guest, Jun 13, 2005
    #1
    1. Advertising

  2. Guest

    Brock Allen Guest

    You can handle the DataGrid's ItemDataBound event. The DataGridItemEventArgs
    passed allows you to access the e.Item which is the row in the DataGrid.
    Find the cell you want, then use FindControl("IDOfYourDDL") to get your DropDownList
    in the Cell. Once you have that, you can do any custom work with it you need
    to.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Hi
    > I have a datagrid defined which I would like to make it editable. So I
    > put
    > in some editcommand and BoundColumn and template column with item
    > template.
    > I don't have problem in setting a column to textbox in
    > edititemtemplate, but
    > how do I set it to dropdownlist and how do I set the selectedIndex?
    > TIA
    >
    Brock Allen, Jun 13, 2005
    #2
    1. Advertising

  3. Guest

    Guest Guest

    Do you mean I should use ItemDataBound event to bind data to the
    dropdownlist control and disable it before the DataGrid got displayed, then
    onEditCommand event, I simply enable the control?

    TIA

    "Brock Allen" <> wrote in message
    news:...
    > You can handle the DataGrid's ItemDataBound event. The

    DataGridItemEventArgs
    > passed allows you to access the e.Item which is the row in the DataGrid.
    > Find the cell you want, then use FindControl("IDOfYourDDL") to get your

    DropDownList
    > in the Cell. Once you have that, you can do any custom work with it you

    need
    > to.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    > > Hi
    > > I have a datagrid defined which I would like to make it editable. So I
    > > put
    > > in some editcommand and BoundColumn and template column with item
    > > template.
    > > I don't have problem in setting a column to textbox in
    > > edititemtemplate, but
    > > how do I set it to dropdownlist and how do I set the selectedIndex?
    > > TIA
    > >

    >
    >
    >
    Guest, Jun 13, 2005
    #3
  4. Guest

    Brock Allen Guest

    To change the Selected item in the DDL, you're going to have to get access
    to the DDL. This can be accomplished by handling the ItemDataBound event
    on the Grid. Oh, one other thing I should have mentioned is that since you're
    only doing this when you edit the row, you should double check for e.Item.ItemType
    == ListItemType.EditItem.

    Oh, just rereading your original post, I think what you're going to want
    is to put a EditItemTemplate. Inside of that put your own DDL. And then,
    yes, in the ItemDataBound you can data bind the DDL to whatever list it needs
    to be.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen

    > Do you mean I should use ItemDataBound event to bind data to the
    > dropdownlist control and disable it before the DataGrid got displayed,
    > then onEditCommand event, I simply enable the control?
    >
    > TIA
    >
    > "Brock Allen" <> wrote in message
    > news:...
    >
    >> You can handle the DataGrid's ItemDataBound event. The
    >>

    > DataGridItemEventArgs
    >
    >> passed allows you to access the e.Item which is the row in the
    >> DataGrid. Find the cell you want, then use FindControl("IDOfYourDDL")
    >> to get your
    >>

    > DropDownList
    >
    >> in the Cell. Once you have that, you can do any custom work with it
    >> you
    >>

    > need
    >
    >> to.
    >>
    >> -Brock
    >> DevelopMentor
    >> http://staff.develop.com/ballen
    >>> Hi
    >>> I have a datagrid defined which I would like to make it editable. So
    >>> I
    >>> put
    >>> in some editcommand and BoundColumn and template column with item
    >>> template.
    >>> I don't have problem in setting a column to textbox in
    >>> edititemtemplate, but
    >>> how do I set it to dropdownlist and how do I set the selectedIndex?
    >>> TIA
    Brock Allen, Jun 13, 2005
    #4
  5. Guest

    Eric Guest

    Hi, Brock.

    I've spent the past 5 hours on this problem, trying to figure out how to
    change the SelectedValue, something that should really only take 30 second.
    I've stumped three other developers in my small office.

    With your help I still can't quite get it.

    I have a static list for the DDL but I need to change the SelectedValue to
    the data that's being edited in the template column of the DataList. I'm not
    inputting the list from a DataReader or anything.

    The problem is I can't access or find the DDL control. I've got a hunch
    that the control I want might not exist when I am trying to access it, since
    it's built on-the-fly (template).

    I've got a dl_EditCommand sub and a dl_ItemDataBound (I just added this one
    as per your suggestion). When I click "Edit", ItemDataBound fires before the
    EditCommand is fired. Is there a method that fires later than these two?

    Help is much appreciated!
    --
    Eric

    "Brock Allen" wrote:

    > To change the Selected item in the DDL, you're going to have to get access
    > to the DDL. This can be accomplished by handling the ItemDataBound event
    > on the Grid. Oh, one other thing I should have mentioned is that since you're
    > only doing this when you edit the row, you should double check for e.Item.ItemType
    > == ListItemType.EditItem.
    >
    > Oh, just rereading your original post, I think what you're going to want
    > is to put a EditItemTemplate. Inside of that put your own DDL. And then,
    > yes, in the ItemDataBound you can data bind the DDL to whatever list it needs
    > to be.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    > > Do you mean I should use ItemDataBound event to bind data to the
    > > dropdownlist control and disable it before the DataGrid got displayed,
    > > then onEditCommand event, I simply enable the control?
    > >
    > > TIA
    > >
    > > "Brock Allen" <> wrote in message
    > > news:...
    > >
    > >> You can handle the DataGrid's ItemDataBound event. The
    > >>

    > > DataGridItemEventArgs
    > >
    > >> passed allows you to access the e.Item which is the row in the
    > >> DataGrid. Find the cell you want, then use FindControl("IDOfYourDDL")
    > >> to get your
    > >>

    > > DropDownList
    > >
    > >> in the Cell. Once you have that, you can do any custom work with it
    > >> you
    > >>

    > > need
    > >
    > >> to.
    > >>
    > >> -Brock
    > >> DevelopMentor
    > >> http://staff.develop.com/ballen
    > >>> Hi
    > >>> I have a datagrid defined which I would like to make it editable. So
    > >>> I
    > >>> put
    > >>> in some editcommand and BoundColumn and template column with item
    > >>> template.
    > >>> I don't have problem in setting a column to textbox in
    > >>> edititemtemplate, but
    > >>> how do I set it to dropdownlist and how do I set the selectedIndex?
    > >>> TIA

    >
    >
    >
    >
    Eric, Jul 13, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Trevor Hartman

    datagrid edititemtemplate for dates

    Trevor Hartman, Jul 16, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    362
    Trevor Hartman
    Jul 16, 2003
  2. Dave
    Replies:
    1
    Views:
    523
  3. Gene McCrory
    Replies:
    5
    Views:
    4,090
    Yan-Hong Huang[MSFT]
    Dec 12, 2003
  4. =?Utf-8?B?bWc=?=
    Replies:
    1
    Views:
    633
    Ashish M Bhonkiya
    May 18, 2004
  5. Replies:
    1
    Views:
    489
    Teemu Keiski
    Jun 22, 2005
Loading...

Share This Page