DropDownList within a DataGrid
-
I have a
DropDownList
within aDataGrid
that displays options based on another column. I'm trying to figure out how I can limit the options based on that other column. Consider this situation: ADataGrid
manages employee work schedules. This table has 3 important columns: name, employee type, and work hours. When edited, the work hours column is aDropDownList
that has the following options: 6-3, 7-4, 8-5, and 9-6. If the employee is a senior manager, however, there should only be two options: 7-4 and 8-5. My first thought was that I would be able to specify theVisible
property on eachListItem
. Unfortunately, there is no such property. Next, I tried to put the logic in theDataGrid
'sEdit
handler. The problem here is that thee.Item
is the view template and not the edit template, which is what I need (so, I can't access theDropDownList
). The only other thing I can think of is to have multipleDropDownList
controls and display the correct one based on the type. This just seems like a horrible solution, tho. I appreciate any help. I don't likeDataGrid
controls and am only using it to keep the code the same as other parts of the system. Michael Flanakin Web Log -
I have a
DropDownList
within aDataGrid
that displays options based on another column. I'm trying to figure out how I can limit the options based on that other column. Consider this situation: ADataGrid
manages employee work schedules. This table has 3 important columns: name, employee type, and work hours. When edited, the work hours column is aDropDownList
that has the following options: 6-3, 7-4, 8-5, and 9-6. If the employee is a senior manager, however, there should only be two options: 7-4 and 8-5. My first thought was that I would be able to specify theVisible
property on eachListItem
. Unfortunately, there is no such property. Next, I tried to put the logic in theDataGrid
'sEdit
handler. The problem here is that thee.Item
is the view template and not the edit template, which is what I need (so, I can't access theDropDownList
). The only other thing I can think of is to have multipleDropDownList
controls and display the correct one based on the type. This just seems like a horrible solution, tho. I appreciate any help. I don't likeDataGrid
controls and am only using it to keep the code the same as other parts of the system. Michael Flanakin Web LogWell the DataGrid is powerful but Microsoft never intended for it be used without being extended for custom uses. It comes out of the box like a "Jack of all trades" I see 2 options 1) implement the ItemDataBound even and modify the list there. Just simply delete options you don't need. 2) Extend a DataColumn to provide some custom features to ontrol the drop down list/ I would do #1 since its easy 1 line of code equals many bugs. So don't write any!!
-
I have a
DropDownList
within aDataGrid
that displays options based on another column. I'm trying to figure out how I can limit the options based on that other column. Consider this situation: ADataGrid
manages employee work schedules. This table has 3 important columns: name, employee type, and work hours. When edited, the work hours column is aDropDownList
that has the following options: 6-3, 7-4, 8-5, and 9-6. If the employee is a senior manager, however, there should only be two options: 7-4 and 8-5. My first thought was that I would be able to specify theVisible
property on eachListItem
. Unfortunately, there is no such property. Next, I tried to put the logic in theDataGrid
'sEdit
handler. The problem here is that thee.Item
is the view template and not the edit template, which is what I need (so, I can't access theDropDownList
). The only other thing I can think of is to have multipleDropDownList
controls and display the correct one based on the type. This just seems like a horrible solution, tho. I appreciate any help. I don't likeDataGrid
controls and am only using it to keep the code the same as other parts of the system. Michael Flanakin Web LogYou can access the ddl in the edit event psuedo.. ListItemType li = e.Item.ListItemType if(li == ListItemType.EditItemType) { DropDownList ddl = e.Item.FindControl('ddlABC') as DropDownList if(Employee.Type == 'Manager') etc... } APD
-
You can access the ddl in the edit event psuedo.. ListItemType li = e.Item.ListItemType if(li == ListItemType.EditItemType) { DropDownList ddl = e.Item.FindControl('ddlABC') as DropDownList if(Employee.Type == 'Manager') etc... } APD
When I tried it in the edit event, I didn't use the
ListItemType
property, but I did try to find the control and it wasn't found. Here's my code...DropDownList list = e.Item.FindControl("hoursList") as DropDownList;
Label type = e.Item.FindControl("employeeType") as Label;
if ( type != null )
{
if ( type.Text != "Manager" ) list.Add("6-3");
list.Add("7-4");
list.Add("8-5");
if ( type.Text != "Manager" ) list.Add("6-3");
}This doesn't work because the
hoursList
isn't found. Also, the only way the employeeType is found is if it's part of theItemTemplate
. So, what's happening is thee.Item
is theItemTemplate
. I'm fine with that, but there has to be a way to get theEditItemTemplate
, too, since it's the current request. Michael Flanakin Web Log -
I have a
DropDownList
within aDataGrid
that displays options based on another column. I'm trying to figure out how I can limit the options based on that other column. Consider this situation: ADataGrid
manages employee work schedules. This table has 3 important columns: name, employee type, and work hours. When edited, the work hours column is aDropDownList
that has the following options: 6-3, 7-4, 8-5, and 9-6. If the employee is a senior manager, however, there should only be two options: 7-4 and 8-5. My first thought was that I would be able to specify theVisible
property on eachListItem
. Unfortunately, there is no such property. Next, I tried to put the logic in theDataGrid
'sEdit
handler. The problem here is that thee.Item
is the view template and not the edit template, which is what I need (so, I can't access theDropDownList
). The only other thing I can think of is to have multipleDropDownList
controls and display the correct one based on the type. This just seems like a horrible solution, tho. I appreciate any help. I don't likeDataGrid
controls and am only using it to keep the code the same as other parts of the system. Michael Flanakin Web LogI decided to add a data source to the
DataGrid
. The data source is simply a method that returns aListItemCollection
:<asp:DropDownList id="hoursList" runat="server"
DataSource='<%# GetHours(DataBinder.Eval(Container.DataItem, "EmployeeType")) %>'
DataTextField="Text" DataValueField="Value" />Michael Flanakin Web Log