I have two dropdowns inside on an InsertItemTemplate of a details view. The first dropdown is the number of hours worked 0 - 24. The second dropdown is minutes worked 0, 15, 30, 45. The rule is some time value has to be entered. Ie., if hours = 0 then some minute value besides 0 has to be added, if hours > 0 then minutes can be 0.
I am trying to use a custom validator with an OnServerValidate event. When I tell the validator which control to validate (minutes) it sends the value of the minutes dropdown to the function. The problem is I have no way to get the value of the hours dropdown to make my comparison checks. It seems that getting the value of template fields inside of detailsview and formview is very difficult to do unless they are sent as arguments to a function.
Does anyone know the way I can the value of the hours dropdown in this case?
I hope this is clear. Thanks in advance.
Tom
There are a lot of ways you could do this. You could just leave your code as is. Once you have your minutes dropdownlist, you can do a FindControl on your dropdownlists parent property. Now if there is multiple template 'columns' you might need to do it on the parent of the parent.
Eg.
DropDownList ddl = (DropDownList)(ddlMinutes.Parent.FindControl("ddlHours"));
or
DropDownList ddl = (DropDownList)(ddlMinutes.Parent.Parent.FindControl("ddlHours"));
Now you might need to do some casting of the parent... I am not near VS to test any of this out so you might need to work out the exact code.
No comments:
Post a Comment