Adding a control to the DataGrid collection controls

  • Thread starter Giorgio Parmeggiani
  • Start date
G

Giorgio Parmeggiani

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
 
J

Jacob Yang [MSFT]

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 (e-mail address removed).

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.
 
J

Jacob Yang [MSFT]

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:[email protected]]
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.
 
J

Jacob Yang [MSFT]

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.
 
J

Jacob Yang [MSFT]

From: Jacob Yang
Sent: October 20, 2003 13:28
To: '(e-mail address removed)'
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: (e-mail address removed) [mailto:[email protected]]
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top