none
IListSource 不包含任何数据源 RRS feed

  • 问题

  • 前台代码:

           起始日期<asp:TextBox ID="startday" runat="server"></asp:TextBox>
           截止日期<asp:TextBox ID="endday" runat="server"></asp:TextBox>
           客户名称<asp:DropDownList ID="cust_code" runat="server" DataSourceID="listcustoner"  DataTextField="Name" DataValueField="Code"   Height="36px" Width="149px">
            </asp:DropDownList>
            <asp:SqlDataSource ID="listcustoner"  runat="server"
                ConnectionString="<%$ ConnectionStrings:DB_RGK_U9V21_DATAConnectionString %>"
                SelectCommand="SELECT A.Code, A1.Name FROM CBO_Customer AS A LEFT OUTER JOIN CBO_Customer_Trl AS A1 ON A.ID = A1.ID">
            </asp:SqlDataSource>
            项目<asp:TextBox ID="proj" runat="server" Width="128px"></asp:TextBox>

            组 织<asp:DropDownList ID="org" runat="server" DataSourceID="listorg"
                DataTextField="Name" DataValueField="Code" Height="19px" Width="137px">
            </asp:DropDownList>
            <asp:SqlDataSource ID="listorg" runat="server"
                ConnectionString="<%$ ConnectionStrings:DB_RGK_U9V21_DATAConnectionString %>"
                SelectCommand="SELECT A.Code, A1.Name FROM Base_Organization AS A LEFT OUTER JOIN Base_Organization_Trl AS A1 ON A.ID = A1.ID where A.code not in ('CPOrg','JC001','RJKJT','VPOrg','RH001')">
            </asp:SqlDataSource>
     
            <asp:Button ID="bt_submit" runat="server" Text="提交" />

            <asp:GridView ID="GV2" runat="server" AutoGenerateColumns="False"
                Height="125px" Width="908px" AllowPaging="true" OnPageIndexChanging="GV2_PageIndexChanging">
            <Columns>
            <asp:BoundField DataField="Aid" HeaderText="序号"/>
            <asp:BoundField DataField="Atr_date" HeaderText="日期"/>
            <asp:BoundField DataField="Atf_memo" HeaderText="摘要"/>
            <asp:BoundField DataField="SoNo" HeaderText="销售单号"/>
            <asp:BoundField DataField="PJ" HeaderText="项目"/>
            <asp:BoundField DataField="Cust_Code" HeaderText="客户编码"/>
             <asp:BoundField DataField="Cust_ShortName" HeaderText="客户简称"/>
            <asp:BoundField DataField="ShipQtyTUAmount" HeaderText="出货数量"/>
            <asp:BoundField DataField="FinallyPrice" HeaderText="价格"/>
            <asp:BoundField DataField="TotalMoneyFC" HeaderText="出货金额"/>
            <asp:BoundField DataField="TotalMoney_FCMoney" HeaderText="收款金额"/>
            <asp:BoundField DataField="TotalMoney" HeaderText="余额"/>
            </Columns>
            </asp:GridView>

    后台代码:

    Imports System.Data
    Imports System.Data.SqlClient

    Public Class WebForm1
        Inherits System.Web.UI.Page

        Dim sqlconn As SqlConnection = New SqlConnection("server=(local);database=DB_DATA;uid=sa;pwd=123")
        Dim sqladapter As SqlDataAdapter = New SqlDataAdapter()
        Dim sqldataset As DataSet = New DataSet()

        Protected Sub bt_submit_Click(sender As Object, e As EventArgs) Handles bt_submit.Click
            sqladapter.SelectCommand = New SqlCommand()
            sqladapter.SelectCommand.Connection = sqlconn
            sqladapter.SelectCommand.CommandText = "XWM_RGK_XSDZ"
            sqladapter.SelectCommand.CommandType = CommandType.StoredProcedure
            sqladapter.SelectCommand.Parameters.Add("@Param1", SqlDbType.NVarChar).Value = startday.Text
            sqladapter.SelectCommand.Parameters.Add("@Param2", SqlDbType.NVarChar).Value = endday.Text
            sqladapter.SelectCommand.Parameters.Add("@Param3", SqlDbType.NVarChar).Value = cust_code.SelectedValue
            sqladapter.SelectCommand.Parameters.Add("@Param4", SqlDbType.NVarChar).Value = proj.Text      
            sqladapter.SelectCommand.Parameters.Add("@Param6", SqlDbType.NVarChar).Value = org.Text
            sqlconn.Open()
            sqladapter.SelectCommand.ExecuteNonQuery()
            sqladapter.Fill(sqldataset)
            sqlconn.Close()
            GV2.DataSource = sqldataset
            GV2.DataBind()
            sqlconn = Nothing
            sqladapter = Nothing
        End Sub

        Protected Sub GV2_PageIndexChanging(sender As Object, e As GridViewPageEventArgs)
            GV2.DataSource = sqldataset

            GV2.PageIndex = e.NewPageIndex
            GV2.DataBind()
        End Sub
    End Class

    选择日期、客户、项目、组织等条件,点击提交,显示存储过程返回结果集,

    经调试gridview数据能显示出来,但是点击下一页就报“IListSource 不包含任何数据源” ,不知道什么原因,能否帮忙解决一下,谢谢!

    测试,页面显示时直接载入gridview,能出来存储过程返回的结果集(后台直接赋值日期、客户等条件值),且点击下一页也没有问题,不知道是什么问题,是不是

    Protected Sub bt_submit_Click(sender As Object, e As EventArgs) Handles bt_submit.Click 这里的内容没有写对?


    • 已编辑 creda 2012年11月23日 2:33 加强描述
    • 已移动 ThankfulHeart 2012年11月27日 2:37 ASP.NET问题 (发件人:Visual Basic)
    2012年11月22日 9:18

答案

  • 页面来回传输的时候,应该把数据源放入ViewState中为妥:

    Public Class WebForm1
         Inherits System.Web.UI.Page
    
     
        Protected Sub bt_submit_Click(sender As Object, e As EventArgs) Handles bt_submit.Click
        Dim sqlconn As SqlConnection = New SqlConnection("server=(local);database=DB_DATA;uid=sa;pwd=123")
         Dim sqladapter As SqlDataAdapter = New SqlDataAdapter()
         Dim tb As DataTable = New DataTable()
             sqladapter.SelectCommand = New SqlCommand()
             sqladapter.SelectCommand.Connection = sqlconn
             sqladapter.SelectCommand.CommandText = "XWM_RGK_XSDZ"
             sqladapter.SelectCommand.CommandType = CommandType.StoredProcedure
             sqladapter.SelectCommand.Parameters.Add("@Param1", SqlDbType.NVarChar).Value = startday.Text
             sqladapter.SelectCommand.Parameters.Add("@Param2", SqlDbType.NVarChar).Value = endday.Text
             sqladapter.SelectCommand.Parameters.Add("@Param3", SqlDbType.NVarChar).Value = cust_code.SelectedValue
             sqladapter.SelectCommand.Parameters.Add("@Param4", SqlDbType.NVarChar).Value = proj.Text      
             sqladapter.SelectCommand.Parameters.Add("@Param6", SqlDbType.NVarChar).Value = org.Text
    
             sqladapter.SelectCommand.ExecuteNonQuery()
             sqladapter.Fill(tb)
    
             GV2.DataSource = tb
             ViewState("tb")=tb
             GV2.DataBind()
    
         End Sub
     
        Protected Sub GV2_PageIndexChanging(sender As Object, e As GridViewPageEventArgs)
             GV2.DataSource = CType(ViewState("tb"),DataTable)
            GV2.PageIndex = e.NewPageIndex
             GV2.DataBind()
         End Sub
     End Class


    我的博客园
    慈善点击,点击此处
    和谐拯救危机,全集下载,净化人心

    2012年11月23日 7:05

全部回复

  • 页面来回传输的时候,应该把数据源放入ViewState中为妥:

    Public Class WebForm1
         Inherits System.Web.UI.Page
    
     
        Protected Sub bt_submit_Click(sender As Object, e As EventArgs) Handles bt_submit.Click
        Dim sqlconn As SqlConnection = New SqlConnection("server=(local);database=DB_DATA;uid=sa;pwd=123")
         Dim sqladapter As SqlDataAdapter = New SqlDataAdapter()
         Dim tb As DataTable = New DataTable()
             sqladapter.SelectCommand = New SqlCommand()
             sqladapter.SelectCommand.Connection = sqlconn
             sqladapter.SelectCommand.CommandText = "XWM_RGK_XSDZ"
             sqladapter.SelectCommand.CommandType = CommandType.StoredProcedure
             sqladapter.SelectCommand.Parameters.Add("@Param1", SqlDbType.NVarChar).Value = startday.Text
             sqladapter.SelectCommand.Parameters.Add("@Param2", SqlDbType.NVarChar).Value = endday.Text
             sqladapter.SelectCommand.Parameters.Add("@Param3", SqlDbType.NVarChar).Value = cust_code.SelectedValue
             sqladapter.SelectCommand.Parameters.Add("@Param4", SqlDbType.NVarChar).Value = proj.Text      
             sqladapter.SelectCommand.Parameters.Add("@Param6", SqlDbType.NVarChar).Value = org.Text
    
             sqladapter.SelectCommand.ExecuteNonQuery()
             sqladapter.Fill(tb)
    
             GV2.DataSource = tb
             ViewState("tb")=tb
             GV2.DataBind()
    
         End Sub
     
        Protected Sub GV2_PageIndexChanging(sender As Object, e As GridViewPageEventArgs)
             GV2.DataSource = CType(ViewState("tb"),DataTable)
            GV2.PageIndex = e.NewPageIndex
             GV2.DataBind()
         End Sub
     End Class


    我的博客园
    慈善点击,点击此处
    和谐拯救危机,全集下载,净化人心

    2012年11月23日 7:05
  • 谢谢;

    后来我修改 Protected Sub GV2_PageIndexChanging(sender As Object, e As GridViewPageEventArgs)部分

     Protected Sub GV2_PageIndexChanging(sender As Object, e As GridViewPageEventArgs)
            

            GV2
    .PageIndex = e.NewPageIndex
            
     bt_submit_Click( GV2.PageIndex ,e
        
    End Sub

    其实这样也可以,刚开始我忘了是通过点击按钮加载girdview,通过向 bt_submit_Click 传递新的页面索引也可以实现,不过也很谢谢你的解答;

    2012年12月5日 6:57