【问题标题】:How can I call bind method of grid through webmethod如何通过 webmethod 调用网格的绑定方法
【发布时间】:2013-11-12 06:20:50
【问题描述】:

这是我在代码后面绑定的方法,我想通过web方法调用它

Private Sub BindData()
    Dim objtable As New DataTable("projectinfoclass")
    Dim Conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("conString").ConnectionString)
    Dim Cmd As SqlDataAdapter = New SqlDataAdapter("select * from ProjectInfoNew", Conn)

    Cmd.Fill(objtable)
    projectinfolist.Clear()

    For Each dr As DataRow In objtable.Rows
        projectinfolist.Add(New Projectinfoclass With {
            .ProjectNumber = dr("ProjectNumber").ToString(),
            .projectId = dr("Projectid").ToString(),
            .Projectname = dr("ProjectName").ToString(),
            .projectmodifiedDate = dr("ProjectmodifiedDate").ToString(),
            .Recordupdateddate = dr("Recordupdateddate").ToString(),
            .ProjectLocation = dr("ProjectLocation").ToString(),
            .LocationServerName = dr("LocationServerName").ToString(), .ProjectModifiedBy = dr("ProjectModifiedBy").ToString(),
            .DBServer = dr("DBServer").ToString(),
            .DBName = dr("DBName").ToString(),
            .Flag = Nothing})
    Next

    GridView1.DataSource = objtable
    GridView1.DataBind()
 End Sub

【问题讨论】:

    标签: asp.net vb.net gridview data-binding


    【解决方案1】:

    将您的 GridView 放在用户控件中并按照此处的解决方案进行操作:

    How do I get the HTML output of a UserControl in .NET (C#)?

    【讨论】:

      【解决方案2】:

      1) 保留页面代码中的数据源和绑定位,将其余部分移至Web方法中。可以在后面的代码中调用 web 方法并使用结果。 或者 2) 将代码移入上述 Web 方法,但在 aspx 中用作对象数据源,这会删除所有接线背后的代码。

      我希望这就是你所追求的。

      【讨论】:

      • 如何在上面的代码中使用存储过程而不是sql查询
      • 这方面有很多问题、答案和资料,一个简单的搜索就能满足您的所有需求。
      猜你喜欢
      • 1970-01-01
      • 2020-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 2017-10-15
      • 2014-10-10
      • 1970-01-01
      相关资源
      最近更新 更多