在用户控件中使用数据集 [英] Using Dataset in user control

查看:66
本文介绍了在用户控件中使用数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试开发一个包含数据网格的用户控件。



以下是从用户控件剪切的代码

 私人 Dsm 正如 DataSet 

公共 属性 ds() As DataSet
获取
返回 DsM
结束 获取

Set (value As DataSet)
DsM = value
End 设置
结束 属性
公共 Sub Populategrid()
grd.DataSource = Nothing
grd.DataSource = ds
grd.DataBind()
结束 Sub

受保护的 Sub Page_Load( ByVal sender 作为 对象 ByVal e As System.EventArgs)句柄 .Load
Populategrid()

结束 Sub





在.aspx

 <   asp:UpdatePanel     ID   =  UpdatePanel1    runat   = 服务器      UpdateMode  < span class =code-attribute>   = 条件 >  
< ContentTemplate >

< uc1:grtcnt ID = grtcnt1 runat = server / >
< asp:按钮 ID < span class =code-keyword> = btnRefresh runat = server 文字 = 刷新 onclick = btnRefresh_Click / >
< / ContentTemplate >
< / asp:UpdatePanel >





在.aspx.vb





 受保护的  Sub  Page_Load( ByVal  sender 作为 对象 ByVal  e 作为 System.EventArgs)句柄  .Load 
如果 IsPostBack 那么
grtcnt1。 ds = datSet
结束 如果
结束 Sub

受保护的 Sub btnRefresh_Click(发件人作为 对象,e As EventArgs)句柄 btnRefresh1.Click
btnClicked = 1
Label1.Text = DateTime.Now.ToLongTimeString()
grtcnt1.ds = NewdatSet
grtcnt1.Populategrid()
End Sub









我的问题是,



尽管loadi第一次使用ng页面时,将根据数据集(datset)填充数据。但是在我的刷新按钮点击事件中,即使新的/更新的数据在(NewdatSet)中可用,它也没有反映在我的usercontrol网格中

,即使我明确调用绑定数据的方法(Populategrid)。

问候

Sudarsan CR

解决方案

问题通过以下更改来解决用户控制页面加载事件(包括ispostback的检查)。





 受保护的  Sub  Page_Load( ByVal  sender 作为 对象 ByVal  e 正如 System.EventArgs)句柄  .Load 
< big> < b> 如果 IsPostBack 然后
< / big >
Populategrid()
< big> 结束 如果 < / big >
结束 Sub


Hi,

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

Following is code snipped from user control

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


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

解决方案

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


 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


这篇关于在用户控件中使用数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆