CslaDataSource

CslaDataSource

Old forum URL: forums.lhotka.net/forums/t/3301.aspx


dantes posted on Tuesday, July 31, 2007

i have this web apps... i have a gridview and a combobox...
i used the csladatasource to connect the gridview and my business object...

i used the combobox (SelectedIndexChanged) to choose a value to be passed as criteria to the GetList method of my Business Object... and render the gridview back... but the gridview would not change...

'Code

Partial Public Class RadGridSample
    Inherits System.Web.UI.Page

    Private _positionList As PositionList = Nothing
    Private _value As Integer = 0
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _positionList = PositionList.GetList(Nothing)
    End Sub

   Private Sub CslaDataSource1_SelectObject(ByVal sender As Object, ByVal e As Csla.Web.SelectObjectArgs) Handles CslaDataSource1.SelectObject
        e.BusinessObject = _positionList
    End Sub

    Protected Sub RadComboBox1_SelectedIndexChanged(ByVal o As System.Object, ByVal e As Telerik.WebControls.RadComboBoxSelectedIndexChangedEventArgs) Handles RadComboBox1.SelectedIndexChanged
           _positionList = PositionList.GetList(CType(RadComboBox1.SelectedValue, Integer))
  
        Dim e1 As New Csla.Web.SelectObjectArgs
        CslaDataSource1_SelectObject(Me.CslaDataSource1, e1)

    End Sub

JonStonecash replied on Tuesday, July 31, 2007

From the code that you posted, it looks like you are not handling the distinction between the original rendering of the page and the "postback" rendering/processing of the page.  The typical pattern is to have some code in the form load event that tests to see if this call to the page is a postback.  If it is not a postback (meaning this is the first time through the page logic), you would set up the contents of the combo box.  If it is a postback (meaning the second or subsequent time through the page logic), you would respond to the changes in the combo box such as the selected index changed.  If you reinitialize the combo box every time, you will never get the selected index changed event because from the perspective of the ASP.NET logic, you have overwritten the changes each time before they can be recognized and processed. 


Jon Stonecash

xal replied on Tuesday, July 31, 2007

I'll add another thing:

This segment is wrong:
Dim e1 As New Csla.Web.SelectObjectArgs
CslaDataSource1_SelectObject(Me.CslaDataSource1, e1)

It won't do anything on it's own. What you should do is call the grid's DataBind() method. That will trigger the SelectObject event in your csladatasource.


So, what you have to do is wrap check for the combobox's selected value inside the SelectObject event, and only call gridview1.DataBind() from selectedindex changed.

In Page.Load, you should do:
If Not Page.IsPostBack Then
 gridview1.DataBind()
End If


Although from what you're saying, this might not be necessary at all.

Andrés

Copyright (c) Marimer LLC