By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,121 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <no****@stopspamming.com> wrote in message
news:AC**********************************@microsof t.com...
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

Nov 19 '05 #2

P: n/a
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" <no****@stopspamming.com> wrote in message
news:AC**********************************@microsof t.com...
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


Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.