my datagrid does not show up when used as custom control

Discussion in 'ASP .Net Datagrid Control' started by Sumana, Jan 27, 2004.

  1. Sumana

    Sumana Guest

    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
     
    Sumana, Jan 27, 2004
    #1
    1. Advertising

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

    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "Sumana" <> wrote in message
    news:...
    > 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
     
    Alvin Bruney [MVP], Jan 27, 2004
    #2
    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. Replies:
    0
    Views:
    721
  2. Replies:
    1
    Views:
    377
    Teemu Keiski
    Jul 2, 2003
  3. Matt Sokol
    Replies:
    2
    Views:
    386
    Theo Tillotson
    Aug 7, 2003
  4. ton

    Datagrid in Custom Server control Does not show

    ton, Jan 27, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    120
    Alessandro Zifiglio
    Jan 27, 2004
  5. greenflame
    Replies:
    6
    Views:
    152
    greenflame
    Jun 18, 2005
Loading...

Share This Page