我试着解决了,但是还是希望各位能给我指出问题的根本。方法如下:
我一直想或许是数据集合被装载了两遍
而后我在第一次装载控件的中加上了
objDataSet.Reset()结果正常了。但是问题是为什么它会加载两次呢?
或者这并不是真实的原因。各位我还在等确切的答案。
我一直想或许是数据集合被装载了两遍
而后我在第一次装载控件的中加上了
objDataSet.Reset()结果正常了。但是问题是为什么它会加载两次呢?
或者这并不是真实的原因。各位我还在等确切的答案。
不过我想应该和c#差不多
Sub BindGrid()
objDataAdapter.SelectCommand = objCmd
objDataAdapter.SelectCommand.CommandText = "SELECT ArticleOriginal,ArticleID,ArticleFileName,ArticlePic,ArticlePath,ArticleTitle,ArticleTime,ArticleNominate,ArticleHit,ArticleTitleB FROM Article where ArticleID=" + ClassID
objDataAdapter.SelectCommand .Connection = objConn objDataAdapter.Fill(objDataSet)
DataGrid1.DataSource = objDataSet
DataGrid1.PagerStyle.Mode = PagerMode.NumericPages
DataGrid1.PageSize = PageSize
DataGrid1.DataBind()
End Sub
你的"1"是什么啊?这样写不对的,
如果要fill到指定表,那么你这个表要先定义表结构才可以加入到dataset里啊。直接用objDataAdapter.Fill(objDataSet)就行了吧,试试看
objDataSet.Reset()
改成
objDataAdapter.Fill(objDataSet)
DataGrid1.DataSource = objDataSet.Tables(0).DefaultView
试试。可能是DataGrid的问题。
该为:
objDataAdapter.Fill(objDataSet)你不会是在DataGrid1的属性生成器里加如了绑定列,而且又选择了"运行时自动创建列了"吧
不应该的呀
分页下标立即减少到了正常水平,说明数据只输出了一次。各位我还是想知道问题的所在啊。下面我把涉及到的三个文件的code全都贴出来,待各位分析调试:
代码说明:
testdata2.aspx 为调用此控件的aspx
classindex6.ascx 为控件页面
classindex6.ascx.vb 为控件过程代码
目前只有加上classindex6.ascx.vb被我注释掉的objDataSet.Reset()才能正常显示。
注意路径!testdata2.aspx
/////////////////////////////
<%@ Register TagPrefix="pageUnit" TagName="classindex6" Src="classindex6.ascx" %>
<%@ Page Language="vb" AutoEventWireup="true" EnableViewState="True" Codebehind="testdata2.aspx.vb" Inherits="website.testdata2"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>testdata2</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server">
<pageunit:classindex6 id="Classindex6" runat="server" ClassID="other" PageSize=20></pageunit:classindex6>
</form>
</body>
</html>/////////////////////////////classindex6.ascx
/////////////////////////////
<%@ Control Language="vb" EnableViewState="true" AutoEventWireup="true" Codebehind="classindex6.ascx.vb" Inherits="website.classindex6" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:datagrid id="DataGrid1" HeaderStyle-BackColor="#aaaadd" Font-Size="8pt" Font-Name="Verdana"
CellSpacing="0" CellPadding="5" GridLines="Both" BorderWidth="0" PagerStyle-HorizontalAlign="center"
BorderColor="black" AutoGenerateColumns="false" ShowHeader="false" EnableViewState="true"
OnPageIndexChanged="DataGrid1_PageIndexChanged" AllowPaging="True" runat="server">
<HeaderStyle BackColor="#AAAADD"></HeaderStyle>
<Columns>
<asp:HyperLinkColumn Target="_blank" DataNavigateUrlField="ArticleID" DataNavigateUrlFormatString="/active/open.aspx?id={0}"
DataTextField="ArticleTitle" NavigateUrl="sdfsdf">
<ItemStyle Width="320px"></ItemStyle>
</asp:HyperLinkColumn>
<asp:BoundColumn DataField="ArticleHit">
<ItemStyle ForeColor="#999999" Width="5px"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ArticleTime" DataFormatString="{0:d}">
<ItemStyle ForeColor="#999999" Width="90px" HorizontalAlign=Right></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:datagrid>/////////////////////////////classindex6.ascx.vb
/////////////////////////////
Imports System.data
Imports System.data.SqlClient
Imports System.Configuration
Public Class classindex6
'update 2003.7.6
Inherits System.Web.UI.UserControl
Public ClassID As String
Public PageSize As String
Public LineLength As Integer
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid Private objConn As New SqlConnection(ConfigurationSettings.AppSettings("sqldsn"))
Private objCmd As New SqlCommand
Private objReader As SqlDataReader
Private objDataAdapter As New SqlDataAdapter
Private objDataSet As New DataSet Sub BindGrid()
objCmd.CommandText = "SELECT ArticleOriginal,ArticleID,ArticleFileName,ArticlePic,ArticlePath,ArticleTitle,ArticleTime,ArticleNominate,ArticleHit,ArticleTitleB FROM Article where ClassID='" _
+ ClassID + "' and ArticleCheck=1 and ArticleDelete=0 order by ArticleLevel desc,ArticleTime desc"
objCmd.Connection = objConn
objDataAdapter.SelectCommand = objCmd
'objDataAdapter.Fill(objDataSet, "Article")
objDataAdapter.Fill(objDataSet)
DataGrid1.DataSource = objDataSet.Tables(0).DefaultView
'DataGrid1.DataSource = objDataSet.Tables("Article").DefaultView
DataGrid1.PagerStyle.Mode = PagerMode.NumericPages
DataGrid1.PageSize = PageSize
DataGrid1.DataBind()
End Sub
Sub DataGrid1_PageIndexChanged(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
DataGrid1.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub '注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
'objDataSet.Reset()
DataGrid1.CurrentPageIndex = 0
BindGrid()
End If
End SubEnd Class/////////////////////////////
是不是可以自动执行DataGrid1_PageIndexChanged????
将AutoEventWireup设置为空一切ok,ericvan(骨灰虫)分析很准确。谢谢了~~~各位,辛苦了!!!
鞠躬了!!!