Adding a control to the DataGrid collection controls

Discussion in 'ASP .Net Datagrid Control' started by Giorgio Parmeggiani, Oct 9, 2003.

  1. Hi
    I have built a DataGrid custom adding a panel of selection
    automatically produced in base to the columns of the
    DataGrid
    The panel has directly been added to the collection
    controls of the datagrid: datagrid.Controls.Add
    (_panelFilter)

    The problem is that for all the contained controls in the
    panel the event OnPreRender is never recalled, besides for
    the controls DropDownList and other custom controls
    doesn't work the ViewState.

    My question is: Can to directly add some controls to the
    collection of the DataGrid have some problems, can I use
    another way to add the panel of selection?

    Giorgio
    Giorgio Parmeggiani, Oct 9, 2003
    #1
    1. Advertising

  2. Hi Giorgio,

    Thank you for using Microsoft MSDN managed newsgroup.

    Use the Controls collection to manage the child controls contained in a
    data listing control. We can add controls, remove controls, or iterate
    through the server controls in the collection.

    Please refer to the following URL for a simple sample regarding this issue.

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
    frlrfsystemwebuiwebcontrolsbasedatalistclasscontrolstopic.asp

    For your special case, currently I have not a specific answer. Is it
    possible for you to send me a simple testing sample and tell me how to
    reproduce your problems step by step on my side? I certainly appreciate
    your time. My email box is .

    Best regards,

    Jacob Yang
    Microsoft Online Partner Support
    Get Secure! ¨C www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jacob Yang [MSFT], Oct 10, 2003
    #2
    1. Advertising

  3. Hi Giorgio,

    Thank you for your update.

    I am researching the testing sample now. More time is needed for this
    issue. Thank you for your understanding. I will contact you as soon as
    possible.

    Best regards,

    Jacob Yang
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.


    ________________________________________
    From: Giorgio Parmeggiani [mailto:]
    Sent: October 12, 2003 1:27
    To: Jacob Yang
    Subject: Example of adding a control to the DataGrid controls collection

    Hi Jacob

    Thanks for your rapids answer!

    I have prepared an simple example of the DataGrid Custom.
    The class calls DataGridFilter (contained in DataGridFilterExample.zip) and
    is used in the example page default.aspx (contained in
    DataGridFilterTest.zip).

    Calling the page default.aspx is loaded a DataGrid reading the table
    "Clienti" of Northwind.mdb (it uses the database that I have attached)

    In the DataGrid custom I have defined 4 columns (BoundColumnFilter extended
    by BoundColumn) in base to which a panel of filter is created above to the
    DataGrid.

    Every column have an attribute that establishes if he must be visualizes in
    the filter as TextBoxFilter (class extended by TextBox) or DropDownFilter
    (class extended by DropDownList). I have foreseen in the example page three
    columns as TextBox and the last as DropDown.

    You can easily verify that, performing a postback, the TextBox maintains
    his value thanks to the ViewState while the DropDown doesn't maintain it (I
    am forced to recall the method "setChildDataSource" with the parameter
    load=true to manually load the element selected through Request.Form)

    Besides if you put a BreakPoint inside the method OnPreRender of
    DropDownFilter you can easily verify that this is never recalled.

    Where am I wrong? Can you advise me to resolve the problem?

    Thanks still for your interest to my problem.

    Ciao
    Giorgio


    P.S. The example that I have sent you doesn't filter the elements of the
    DataGrid I have removed this it seems for simplifying him/it.
    Jacob Yang [MSFT], Oct 13, 2003
    #3
  4. Hi Giorgio,

    I have done a lot of research regarding this issue and reproduced the
    problem on my side. The followings are my testing steps:

    1. Extract DataGridFilterTest under the wwwroot directory.

    2. In IIS, create DataGridFilterTest as a web application.

    3. Extract DataGridFilterExample.

    4. Open the solution.

    5. Set DataGridFilterTest as the startup project.

    6. Set default.aspx as the startup page.

    7. Set the correct data source path in the web.config file.

    8. Build and run the web application.

    9. Type ¡°Jacob Yang¡± in the Name text field.

    10. Select ¡°Titolare¡± in the Position Dropdownlist.

    11. Click the ¡°Cerca¡± button.

    12. We can see that the ¡°Jacob Yang¡± is maintained but the ¡°Titolare¡±
    is not.

    I have not found a specific solution for your testing sample. Based on my
    research and experience, I would like to share the following information
    with you.

    In the custom control, you are first setting the properties and adding the
    list items. After that you are adding the control to the control tree.
    Note that we don't start tracking the viewstate until unless the control is
    added to the control tree. So, we don't save the viewstate for these
    listitems. Please refer to the following URLs regarding this issue.

    http://msdn.microsoft.com/chats/vstudio/vstudio_082202.asp
    ¡°¡­
    : bryan : I have a custom server control that has a DropDownList called
    List in it. I got AutoPostBack to work on the list by adding the list to
    the controls collection, but whenever it posts back, the SelectedIndex = 0.
    ¡­¡±
    http://www.dotnet247.com/247reference/msgs/7/36488.aspx

    http://www.dotnet247.com/247reference/msgs/6/31629.aspx
    ¡°I have a dropdownlist on my asp.net form. When I select an item in the
    dropdownlist it highlights and appears at the top of the list. But when I
    click my submit button and redisplay my page the first item in the
    dropdownlist appears not the item I selected. How can I keep the selected
    item highlighted?
    ¡­¡±

    I hope it helps.

    Best regards,

    Jacob Yang
    Microsoft Online Partner Support
    Get Secure! ¨C www.microsoft.com/security
    This posting is provided ¡°as is¡± with no warranties and confers no rights.
    Jacob Yang [MSFT], Oct 14, 2003
    #4
  5. From: Jacob Yang
    Sent: October 20, 2003 13:28
    To: ''
    Subject: RE: Adding a control to the DataGrid collection controls

    Hi Giorgio,

    I am glad to know that the problem is resolved in your testing sample.

    Based on my research and experience, your solution for the example project
    is correct. I am not sure about when it does not work in your production
    code.

    Looking at the nature of this issue, I would highly recommend you contact
    Microsoft Product Support Services since it would require intensive
    troubleshooting which would be done quickly and effectively with direct
    assistance from a Microsoft Support Professional. Thank you for your
    understanding.

    Microsoft support home page:
    http://support.microsoft.com.
    To view support options:
    http://support.microsoft.com/default.aspx?scid=sz;en-us;top.
    To submit an online request:
    http://support.microsoft.com/default.aspx?scid=fh;en-us;incidentsubmit.

    I hope it helps.

    Best regards,

    Jacob Yang
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.


    -----Original Message-----
    From: [mailto:]
    Sent: October 18, 2003 17:50
    To: Jacob Yang
    Subject: RE: Adding a control to the DataGrid collection controls

    Hi Jacob

    Thankyou for your response.

    I have tried following your indications and are successful to resolve the
    problem in the example that I have made to see you.
    In order to resolve the problem I have:

    - In the OnInit method (override) created dynamically the filter panel.
    - In the OnLoad method (override) added the panel to the collection
    controls

    So the viewstate is correctly loaded.

    But in my production code (is more complicated) the problem is not resolved
    and the viewstate seems not to be loaded.

    Do you think that my solution for the example project is correct ?? How can
    i find a solution for my production code?

    Can i send you a copy of my production code??

    Thankyou in advance!

    Giorgio

    Jacob Yang
    Microsoft Online Partner Support
    Get Secure! ¨C www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jacob Yang [MSFT], Oct 22, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeremy Ames

    Adding controls to Page.Controls collection

    Jeremy Ames, Mar 4, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    1,423
    Peter Blum
    Mar 5, 2004
  2. Øyvind Isaksen
    Replies:
    1
    Views:
    936
    Øyvind Isaksen
    May 18, 2007
  3. Chad Scharf
    Replies:
    3
    Views:
    851
    Chad Scharf
    Oct 18, 2007
  4. Don
    Replies:
    0
    Views:
    139
  5. Replies:
    1
    Views:
    322
Loading...

Share This Page