locked
Custom page with Dynamic Data and Multiple ComboBoxes RRS feed

  • Question

  • User-326746839 posted

    I want to create a custom ASP.Net C# dynamic data page. This page should work (ideally) like this:

    1. It will display a line (a row at a time) of a GridView containing four columns: a Label containig the text of one question, a ComboBox for choosing data, an empty TextBox and a command buttong for saving the data and passing to the next row
    2. The ComboBox will be populated with data coming from an entity (a different entity for each row of the GridView)
    3. After making selection in the ComboBox the selected text should be copied to the TextBox
    4. Afte r saving the data from that row the gridView will display the next row containing the same elements like the firts one BUT populating the ComboBox with values coming from a 2nd entity and so on for every new row

    Process will end when all entities pertaining to this process (which will be defined somehow in the code behind of the page) have been used

    Then the text contained in all TextBoxes will be concatenated in a single string

    Best regards

    Carlos N. Porras
    (El Salvador) 

    Monday, April 22, 2013 7:00 PM

Answers

  • User-330204900 posted

    What you do is iterate through the GridView Rows collection at DataBind and thenfor each cell do FindControl of Type FieldTemplateUserControl :)

    /// <summary>
    /// Finds the control recursive.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="root">The root.</param>
    /// <returns></returns>
    public static T FindControlRecursive<T>(this Control root) where T : Control
    {
        var control = root as T;
        if (control != null)
            return control;
    
        foreach (Control Ctl in root.Controls)
        {
            T FoundCtl = Ctl.FindControlRecursive<T>();
    
            if (FoundCtl != null)
                return FoundCtl;
        }
        return null;
    }

    This is the extension method I use it finds a control of Type

    i.e.

    var selectButton = row.Cells[0].FindControlRecursive<LinkButton>();
    

    here I am using it to find a LinkButton, there are also two other variants

    /// <summary>
    /// Finds the control recursive.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="root">The root.</param>
    /// <param name="Id">The id.</param>
    /// <returns></returns>
    public static T FindControlRecursive<T>(this Control root, string Id) where T : Control
    {
        var control = root as T;
        if (control != null && root.ID == Id)
            return control;
    
        foreach (Control Ctl in root.Controls)
        {
            T FoundCtl = Ctl.FindControlRecursive<T>(Id);
    
            if (FoundCtl != null)
                return FoundCtl;
        }
        return null;
    }
    

    This finds a control of type with an specific ID

    /// <summary>
    /// Get the control by searching recursively for it.
    /// </summary>
    /// <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)
            return Root;
    
        foreach (Control Ctl in Root.Controls)
        {
            Control FoundCtl = FindControlRecursive(Ctl, Id);
    
            if (FoundCtl != null)
                return FoundCtl;
        }
        return null;
    }
    

    This just finds a control with a specific ID :)
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 12, 2013 5:21 AM

All replies

  • User-326746839 posted

    Hi,

    I must add that I know the way in which I could add to my custom page a GridView containing the customized columns with 30 different ComboBoxes and wth 30 different DataSources .... but that's not the point in doing things Dynamic Data's way ... I guess !!!

    The main inconvenient of doing that way is that I will be calling 30 different queries in order to fill 30 ComboBoxes all at once .... which seems very inapropriate in the matter of performance and unnecessary overloadoiing of the CPU's processor, isn't it?

    Carlos N. Porras
    (El Salvador) 

    Thursday, April 25, 2013 8:20 AM
  • User646586705 posted

    Dynamic Data's strong point is CRUD-style applications. A survey application will require so much customization you're better off with  straight asp.net webforms. 

    Thursday, May 2, 2013 4:45 AM
  • User-326746839 posted

    Hi,

    Sorry but I disagree with you. Customizing is also part of Dynamic Data and iterating through a GridView as to create a loop for displaying a single row at a time doesn't seem to me as an obstacle for going ahead with this kind of situations for going with Dynamic Data

    Best regards

    CArlos N. Porras
    (El Salvador) 

    Thursday, May 2, 2013 12:53 PM
  • User-330204900 posted

    Hi Teyc, I am inclined to agree with you (sorry Carlos) I too would just create a custom app for a survey, but you can still use DD with that using simple DD :)

    Friday, May 10, 2013 12:37 PM
  • User-326746839 posted

    Hola Señor Naughton,

    Best regards for you and your family. I wish your health is improving greatly and that you will be fully recovered pretty soon.

    On the matter of this question is like dissapointing to go and went again to some of the questions that have never been answered by the Dynamic_Data's Microsoft_Development_Team (I wish underscores will do their job) on the matter of NOT showing how data controls work.

    I am not complaining whatsoever, just making a remark on swomething that (according to me) is pure and absolute truth

    They let you use the controls and fill them with data but they have never teached how to do all the deploying stuff of those controls while they are been displayed on the screen: "ROW BY ROW" ... iterating in the code behind from top to bottom of the GridView

    It will be really simple if you knew how to deal with the deploymentyt of a GridView by means of iterating through it.

    Somethin like you do when writing HTML code: first goes the declaration of the page, then the header, then the title, then the script langauge used, then the CSS file if any, then the body, then ..... etc. etc. etc. Dynamic Data shows you also how to do the HTML part BUT THAT PART IS NOT ENOUGH because you should also be shown "how to do that in the Code Behind File ALSO" so you can build your GridView on the fly (regardless of the HTML code)

    In that way you could be allowed to do some calculations and many other fancy stuff whiel deploying a single line of a GridView (a row at a time only)

    That will answer this and many other thousand questions posted here in this forum 

    And yes ..... Sorry ... I know I'm kind of stubborn and boring :(

    Carlos N. Porras
    (El Salvador) 

    Saturday, May 11, 2013 10:17 AM
  • User-330204900 posted

    Hi Carlos, I'm getting better, slowly does it :) and as far as what you are saying here

    It will be really simple if you knew how to deal with the deploymentyt of a GridView by means of iterating through it.

    DD was designed with the idea of getting away from all that :) you can iterrate through a GridView's rows and mess around with the firld templates just debug away and look at what you get but the issue you will have is that you never know what the DataControl will be. it's not too complicated but it is messy I prefer to write generic page and field templates. It just goes against the grain after so long developing the DD way.

    Saturday, May 11, 2013 11:25 AM
  • User-326746839 posted

    Hi,

    Anyway, if Ia m going to customize Ui steel need to do the iterations .... were can I finf literature on this

    Carlos N. Porras
    (El Slavador) 

    Saturday, May 11, 2013 8:04 PM
  • User-330204900 posted

    What you do is iterate through the GridView Rows collection at DataBind and thenfor each cell do FindControl of Type FieldTemplateUserControl :)

    /// <summary>
    /// Finds the control recursive.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="root">The root.</param>
    /// <returns></returns>
    public static T FindControlRecursive<T>(this Control root) where T : Control
    {
        var control = root as T;
        if (control != null)
            return control;
    
        foreach (Control Ctl in root.Controls)
        {
            T FoundCtl = Ctl.FindControlRecursive<T>();
    
            if (FoundCtl != null)
                return FoundCtl;
        }
        return null;
    }

    This is the extension method I use it finds a control of Type

    i.e.

    var selectButton = row.Cells[0].FindControlRecursive<LinkButton>();
    

    here I am using it to find a LinkButton, there are also two other variants

    /// <summary>
    /// Finds the control recursive.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="root">The root.</param>
    /// <param name="Id">The id.</param>
    /// <returns></returns>
    public static T FindControlRecursive<T>(this Control root, string Id) where T : Control
    {
        var control = root as T;
        if (control != null && root.ID == Id)
            return control;
    
        foreach (Control Ctl in root.Controls)
        {
            T FoundCtl = Ctl.FindControlRecursive<T>(Id);
    
            if (FoundCtl != null)
                return FoundCtl;
        }
        return null;
    }
    

    This finds a control of type with an specific ID

    /// <summary>
    /// Get the control by searching recursively for it.
    /// </summary>
    /// <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)
            return Root;
    
        foreach (Control Ctl in Root.Controls)
        {
            Control FoundCtl = FindControlRecursive(Ctl, Id);
    
            if (FoundCtl != null)
                return FoundCtl;
        }
        return null;
    }
    

    This just finds a control with a specific ID :)
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 12, 2013 5:21 AM