Last post Sep 15, 2014 01:07 PM by IranianCuriousBoy
Sep 06, 2014 07:51 AM|IranianCuriousBoy|LINK
I'm using DynamicField and DynamicControl in a GridView and in RowCommand event I want to access values of these columns. How can I do that because GridViewRow FindControl method needs an Id and DynamicField has no Id. This method returns DynamicControl
for templated fields but I cannot find the value! the followng is a sample of columns:
<asp:DynamicField DataField="MonthDay" />
<asp:TemplateField HeaderText="Corrected Day">
<asp:DynamicControl runat="server" ID="CorrectedDayDynamicControl"
DataField="CorrectedDay" Mode="Edit" />
Sep 07, 2014 07:04 AM|sjnaughton|LINK
Hi Ali, I developed a FindControl extension method for this:
/// Get the control by searching recursively for it.
/// <param name="Root">The control to start the search at.</param>
/// <param name="Id">The ID of the control to find</param>
/// <returns>The control the was found or NULL if not found</returns>
public static Control FindControlRecursive(this Control Root, string Id)
if (Root.ID == Id)
foreach (Control Ctl in Root.Controls)
Control FoundCtl = FindControlRecursive(Ctl, Id);
if (FoundCtl != null)
/// Finds the control recursive.
/// <typeparam name="T"></typeparam>
/// <param name="root">The root.</param>
public static T FindControlRecursive<T>(this Control root) where T : Control
var control = root as T;
if (control != null)
foreach (Control Ctl in root.Controls)
T FoundCtl = Ctl.FindControlRecursive<T>();
if (FoundCtl != null)
you can search for the control with the field name or you can get a particular Type i.e. just of Type FieldTemplate or the actual type of the specific field template.
Now to why are you doing this? I only ask because there may be an easier way than what you are doing :)
Sep 08, 2014 06:11 AM|IranianCuriousBoy|LINK
The case is that I have a class and it has nothing to do with EF and other DB related technologies. It is populated and I want to use GridView to list the data. I thought it's a good idea to use DD to show fields and it worked partially.
I think there is no way to access a field data when the DynamicField is used. In the case of using DynamicControl the first method returns null but the FindControl do find the DynamicControl but there is no way to access the data in the control. I remember
when I worked on field templates, there was FieldValue that had the data. It seems that DynamicControl does not contain the data but is responsible for finding appropriate field template. Is there any way?
Sep 08, 2014 07:23 AM|sjnaughton|LINK
Hi you are correct you can still get the value however by using the DataControl property and parse the control type.
Sep 09, 2014 09:33 AM|IranianCuriousBoy|LINK
DynamicControl does not have DataControl property. Please elaborate.
Sep 09, 2014 10:56 AM|sjnaughton|LINK
But that is just a wrapper for FieldTemplateUserControl :)
Sep 09, 2014 12:52 PM|IranianCuriousBoy|LINK
Where can I find this wrapper for FieldTemplateUserControl(DataControl Property)?
Sep 10, 2014 03:45 AM|sjnaughton|LINK
if you debug look at the DynamicControl you will see your Field Template inside.
Sep 13, 2014 06:38 AM|IranianCuriousBoy|LINK
I did not find the field value. Have you got any practical use of it(in the forms of an article, etc)
Sep 15, 2014 05:40 AM|sjnaughton|LINK
Hi Ali, no I never get a value like that, if you can tell me what you are trying to achieve I may have another method I can direct you to.
Sep 15, 2014 01:07 PM|IranianCuriousBoy|LINK
Thanks Steve. I told you what I'm trying to do. There is no problem because I used non DD controls and they are working fine. I was just curious about the possibility and the reason of using DD controls was that I like DD and the way of DD programming very