Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to develop a user control which has datagrid in it.

Following is code snipped from user control
VB
 Private Dsm As DataSet
    
  Public Property ds() As DataSet
        Get
            Return DsM
        End Get

        Set(value As DataSet)
            DsM = value
        End Set
    End Property
Public Sub Populategrid()
        grd.DataSource = Nothing
        grd.DataSource = ds
        grd.DataBind()
End Sub

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Populategrid()

    End Sub


In the .aspx
ASP.NET
<asp:UpdatePanel ID="UpdatePanel1" runat="server"  UpdateMode ="Conditional">
          <ContentTemplate>

             <uc1:grtcnt ID="grtcnt1"  runat="server"   />
             <asp:Button ID="btnRefresh" runat="server" Text="Refresh" onclick="btnRefresh_Click" />
         </ContentTemplate>
     </asp:UpdatePanel>


in the .aspx.vb


VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            grtcnt1.ds=datSet
        End If
    End Sub

Protected Sub btnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh1.Click
        btnClicked = 1
        Label1.Text = DateTime.Now.ToLongTimeString()
grtcnt1.ds=NewdatSet
grtcnt1.Populategrid()
            End Sub




My problem is,

While loading page for the first time, data are populated based on the dataset (datset). But on my refresh button click event,even though new/updated data is available in (NewdatSet) it is not getting reflected in my usercontrol grid
even though I make an explicit call to method that bind the data(Populategrid).
Regards
Sudarsan C.R
Posted
Comments
Sinisa Hajnal 17-Oct-14 2:41am    
Where does NewdatSet come from? Are you sure your new data is there? Set breakpoints in btnRefresh and step through the code. See what gets called when. In your control, check that populate grid uses your new data set. You know, debug the problem.
Sudarsan C.R 17-Oct-14 9:03am    
Yes... NewdatSet has the new value while debugging but the main problem is grid is not get reflected with new dataset value even though there is a explicit call to populate the grid content.

1 solution

Issue was sort out with the below change to the user control page load event (include the check for ispostback).


VB
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
<big>If Not IsPostBack Then
</big>
        Populategrid()
 <big>End If</big>
    End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900