Re: Custom Datagrid disappearing on Postback



Thanks Jeff,
if I remove the "IF" in the page load statement then yes it works, but then
I am hitting the database on every postback.
With the MS datagrdd I can just fill the dataset/bind the grid on the
initial page load in the IF Not IsPostBack statement

What is my datagrid missing thats different from MS standard datagrid?

thanks,
Greg


"Jeff" <jeffmagill@xxxxxxxxx> wrote in message
news:1165256222.602754.189870@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
My guess would be that since youre populating your datagrid in the code
behind, that the data is not being saved in the viewstate.

What happens when you take the if statement out of the Page.Load
handler and just call BindList every time the page loads?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

BindList()

End Sub



GJH wrote:
I have a Web Custom Control datagrid written in VB.NET and when the page
does a postback from a Selected Index or Sort command the datagrid
disappears??? anyone know why?
thanks

here is the control's code:

Imports System.ComponentModel

Imports System.Web.UI

<DefaultProperty("Text"), ToolboxData("<{0}:dgTest
runat=server></{0}:dgTest>")> Public Class dgTest

Inherits System.Web.UI.WebControls.DataGrid

Dim _text As String

<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)

Me.EnsureChildControls()

MyBase.Render(output)

End Sub

Protected Overrides Sub OnInit(ByVal e As System.EventArgs)

Me.EnsureChildControls()

End Sub

End Class




Here is my webpage

Dim mySort As String

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then

BindList()

End If

End Sub

Private Sub BindList(Optional ByVal sort As String = "")

Dim query As String = "select * from employees"

Dim da As New SqlDataAdapter(query, cnn)

Dim ds As New DataSet

Try

da.Fill(ds, "employees")

ds.Tables(0).DefaultView.Sort = sort



DgTest1.DataSource = ds

DgTest1.DataMember = "employees"

DgTest1.DataBind()

Catch ex As Exception

Response.Write(ex.Message)

End Try

End Sub

Private Sub GJHAddToCartDataGrid1_SortCommand(ByVal source As Object,
ByVal
e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
GJHAddToCartDataGrid1.SortCommand

mySort = e.SortExpression & " ASC"

BindList(mySort)

End Sub

Private Sub DgTest1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles DgTest1.SelectedIndexChanged

Response.Write("hi")

End Sub



.



Relevant Pages

  • RE: jpgs not showing on forms
    ... Rather than embed the pictures in the database store the paths to the JPEG ... Private Sub cmdAddImage_Click ... Dim strAdditionalTypes As String, strFileList As String ... Private Sub cmdDeleteImage_Click ...
    (microsoft.public.access.gettingstarted)
  • Re: Playing an AVI video
    ... You'd use the "window avi handle" MCI command string. ... Dim mlRet As Long ... Private Sub CenterObject ...
    (microsoft.public.vb.general.discussion)
  • Re: Multi-image Bitmap Extraction
    ... Private Sub Form_Load ... cFileName As String * MAX_PATH ... Dim WFD As WIN32_FIND_DATA, hFile As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: Working Transactions somehow started not to work
    ... ÖA> Private Sub Form_Open ... ÖA> Dim strSqlMain As String ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Custom textbox in Userform
    ... Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ... Function IsValid(strText As String) As Boolean ...
    (microsoft.public.excel.programming)

Loading