Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / January 2004

Tip: Looking for answers? Try searching our database.

Datagrid in Custom Server control Does not show

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ton - 27 Jan 2004 11:21 GMT
Hi,
I've created a custom server control dbList which contains a datagrid

In my CreateChildControls sub I add the control
Controls.Add(Grid)

In my Fill sub I have this code (Fill can be executed from a button on the
page like dbList.Fill)

sqlConn.ConnectionString = "workstation id=VRS7;packet size=4096;user
id=Sa;data source=VRSSERVER;persist security info=False;initial
catalog=Sales"

sqlAdap = New SqlClient.SqlDataAdapter("select top 50 * from tuning",
sqlConn.ConnectionString) '' ConnectionString

sqlAdap.Fill(DS, "Tuning")

grid.DataSource = DS

grid.Visible = True

grid.BorderStyle = BorderStyle.Solid

grid.DataBind()

CreateChildControls()

After pressing the buttons nothing happens.

I use:

Imports System

Imports System.Web

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.Web.UI.HtmlControls

Imports System.ComponentModel

Imports System.Web.SessionState

Imports System.Data

Imports System.Data.SqlClient

and my declaration is:

Dim grid As New DataGrid

Dim sqlConn As New SqlClient.SqlConnection

Dim sqlAdap As SqlClient.SqlDataAdapter

Dim DS As New DataSet

When I add a grid to my page and I use the same code as in de fill command,
the datagrid will be visible.

What is wrong ??

Ton
Alessandro Zifiglio - 27 Jan 2004 15:51 GMT
What you are doing wrong is that your grid is being filled only when the
button is clicked. Add all code that adds your datagrid and binds data to it
somewhere else where it will always be run even after page postback. This is
a requirement for dynamically added controls. To work around your problem
that is still continue to add your datgrid on button click, use viewstate to
set a flag and check this flag in your createchildcontrols method, forcing
the code that added your control to the controls collection to fire even
after a postback.

To better understand what mean, follow up on this post, the last post in
particular.

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=ImVLb.1434%2
4nC1.287%40news.edisontel.com&rnum=1&prev=/groups%3Fq%3DAdd%2Bcontrol%2Bto%2Basp
:PlaceHolder%2Bon%2Basp.net%2Bpage%2Bfrom%2Buser%2Bcontrol%2Bon%2Bsame%2Bpage%26
hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3DImVLb.1434%2524nC1.287%2540ne
ws.edisontel.com%26rnum%3D1


The scenario there is a little different however you can see how viewstate
is being applied. Use that logic. Instead of page_load, use the
createchildcontrols method.

> Hi,
> I've created a custom server control dbList which contains a datagrid
[quoted text clipped - 62 lines]
>
> Ton

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.