Displaying drop-down list boxes for every row in a DataGrid \ Repe

Discussion in 'ASP .Net' started by =?Utf-8?B?RXJpYyBEYW4=?=, Jan 18, 2005.

  1. Hi,

    Even tough I was able to implement what I want in a weird and non efficient
    way, I would like to get an opinion what is the right way to achieve my task:

    Scenario:
    • Display a DataGrid that contains rows from a table from a databse (so far
    easy).
    • I would like to add a column to the DataGrid that will be a drop-down list
    so the user will be able to select a value from a pre-defined list of values
    for every row in the DataGrid. (every row should have a drop-down)
    • When the user will post back the form I would like to refer to every value
    in the drop-down list by name.
    • In order to implement this I used a TemplateColumn in the DataGrid, but I
    had a hard time giving a name to the <select> element so I will be able to
    refer to it when the form will be posted back. I have used a weird syntax
    (with data binding syntax since the container is not the DataGrid but a
    DataGrid item) to create a unique name for each one of the <select> elements.
    This caused the Design-View in Visual Studio to not be able to display the
    page even though it did work at run time.


    Somehow I feel that I took the wrong way to display a drop-down for each and
    every row in the data grid.

    Any opinions?

    --
    Thanks
    Eric
    =?Utf-8?B?RXJpYyBEYW4=?=, Jan 18, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?RXJpYyBEYW4=?=

    Jakub Guest

    i thing simpliest way is to use DropDownList instead of select control
    your code may be like this:

    <asp:datagrid id="mygrid"
    ....
    <ItemTemplate>
    <asp:DropDownList id="MyList" runat="server" />
    <ItemTemplate>...

    and in your postback handler you can use:
    foreach (DataGridItem item in mygrid.Items)
    {
    if (item.ItemType = ListItemType.Item || item.ItemType =
    ListItemType.AlternatingItem)
    {
    DropDownList list = item.FindControl("MyList") as DropDownList;
    ...
    }
    }

    "Eric Dan" <> wrote in message
    news:...
    > Hi,
    >
    > Even tough I was able to implement what I want in a weird and non

    efficient
    > way, I would like to get an opinion what is the right way to achieve my

    task:
    >
    > Scenario:
    > . Display a DataGrid that contains rows from a table from a databse (so

    far
    > easy).
    > . I would like to add a column to the DataGrid that will be a drop-down

    list
    > so the user will be able to select a value from a pre-defined list of

    values
    > for every row in the DataGrid. (every row should have a drop-down)
    > . When the user will post back the form I would like to refer to every

    value
    > in the drop-down list by name.
    > . In order to implement this I used a TemplateColumn in the DataGrid, but

    I
    > had a hard time giving a name to the <select> element so I will be able to
    > refer to it when the form will be posted back. I have used a weird syntax
    > (with data binding syntax since the container is not the DataGrid but a
    > DataGrid item) to create a unique name for each one of the <select>

    elements.
    > This caused the Design-View in Visual Studio to not be able to display the
    > page even though it did work at run time.
    >
    >
    > Somehow I feel that I took the wrong way to display a drop-down for each

    and
    > every row in the data grid.
    >
    > Any opinions?
    >
    > --
    > Thanks
    > Eric
    Jakub, Jan 18, 2005
    #2
    1. Advertising

  3. Re: Displaying drop-down list boxes for every row in a DataGrid \

    Thanks a lot

    It is definitely the best solution

    Eric

    "Jakub" wrote:

    > i thing simpliest way is to use DropDownList instead of select control
    > your code may be like this:
    >
    > <asp:datagrid id="mygrid"
    > ....
    > <ItemTemplate>
    > <asp:DropDownList id="MyList" runat="server" />
    > <ItemTemplate>...
    >
    > and in your postback handler you can use:
    > foreach (DataGridItem item in mygrid.Items)
    > {
    > if (item.ItemType = ListItemType.Item || item.ItemType =
    > ListItemType.AlternatingItem)
    > {
    > DropDownList list = item.FindControl("MyList") as DropDownList;
    > ...
    > }
    > }
    >
    > "Eric Dan" <> wrote in message
    > news:...
    > > Hi,
    > >
    > > Even tough I was able to implement what I want in a weird and non

    > efficient
    > > way, I would like to get an opinion what is the right way to achieve my

    > task:
    > >
    > > Scenario:
    > > . Display a DataGrid that contains rows from a table from a databse (so

    > far
    > > easy).
    > > . I would like to add a column to the DataGrid that will be a drop-down

    > list
    > > so the user will be able to select a value from a pre-defined list of

    > values
    > > for every row in the DataGrid. (every row should have a drop-down)
    > > . When the user will post back the form I would like to refer to every

    > value
    > > in the drop-down list by name.
    > > . In order to implement this I used a TemplateColumn in the DataGrid, but

    > I
    > > had a hard time giving a name to the <select> element so I will be able to
    > > refer to it when the form will be posted back. I have used a weird syntax
    > > (with data binding syntax since the container is not the DataGrid but a
    > > DataGrid item) to create a unique name for each one of the <select>

    > elements.
    > > This caused the Design-View in Visual Studio to not be able to display the
    > > page even though it did work at run time.
    > >
    > >
    > > Somehow I feel that I took the wrong way to display a drop-down for each

    > and
    > > every row in the data grid.
    > >
    > > Any opinions?
    > >
    > > --
    > > Thanks
    > > Eric

    >
    >
    >
    =?Utf-8?B?RXJpYyBEYW4=?=, Jan 18, 2005
    #3
    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. SirPoonga
    Replies:
    2
    Views:
    738
    Ben Strackany
    Jan 7, 2005
  2. Ami

    Mutliple Drop down list boxes

    Ami, Aug 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    379
    =?Utf-8?B?QXVndXN0aW4gUHJhc2FubmE=?=
    Aug 25, 2006
  3. weiwei
    Replies:
    0
    Views:
    997
    weiwei
    Jan 5, 2007
  4. msimmons
    Replies:
    0
    Views:
    453
    msimmons
    Jul 16, 2009
  5. Replies:
    5
    Views:
    248
Loading...

Share This Page