my datagrid does not show up when used as custom control

S

Sumana

Below is the code, for the datagrid custom control. When i view this
in a aspx page, the text "Hello" shows up but not the datagrid. Anyone
can tell me why?
thanks
sumana

Imports System.ComponentModel
Imports System.Web.UI
Imports System
Imports System.Web
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Web.SessionState
Imports System.Data
Imports System.Data.SqlClient

<DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl1
runat=server></{0}:WebCustomControl1>")> Public Class
WebCustomControl1
Inherits System.Web.UI.WebControls.DataGrid
Dim _text As String
Dim grid As New DataGrid()
Dim cn As New SqlClient.SqlConnection("Initial Catalog=LFBP01;Data
Source=brkdbdn61\brksql01;User Id=YYYD368S;Password=YYYD368S")
Dim da As New SqlClient.SqlDataAdapter("select buyer_cd,buyer_nme
from lftp100_buyer", cn)
Dim DS As New DataSet()

<Bindable(True), Category("Appearance"), DefaultValue("")>
Property [Text]() As String
Get
Return _text
End Get

Set(ByVal Value As String)
_text = Value
End Set
End Property

Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
output.Write([Text])
da.Fill(DS)
grid.DataSource = DS
grid.DataBind()
grid.Visible = True
grid.BorderStyle = BorderStyle.Solid
End Sub

End Class
 
A

Alvin Bruney [MVP]

there is no data in your dataset, modify your code to test for data before
you bind
if(DS != null && DS.Tables[0].Rows.Count > 0)
then bind
otherwise
don't bind
 

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

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top