当前位置:编程学习 > C#/ASP.NET >>

vbc编译时出错,关于控件的一些错误

用vbc编译器编译时出现
name 'Postdg' is not declared
....
只要是关于控件的都是未声明,请高手指教,多谢,在线等...
后台代码:
Imports System.Data
Imports System.Data.OleDb
Imports System.Web.UI.WebControls.DataGrid
Namespace aa
    Public Class admin_PostManage2
        Inherits System.Web.UI.Page
        Dim connstring As String
        Dim myconn As OleDbConnection
        Dim strsql As String
        Public Sub page_load()
            If Session("adminuser") = "" Then
                Response.Redirect("login.aspx")
            Else
                connstring = System.Configuration.ConfigurationManager.AppSettings("conn")
                myconn = New OleDbConnection(connstring)
                If Not IsPostBack Then
                    Postdatabind()
                    ShowStats()
                End If
            End If
        End Sub
        Public Sub Postdatabind()
            Dim myadapter As OleDbDataAdapter = New OleDbDataAdapter()
            Dim ds As DataSet = New DataSet()
            Dim dv As DataView
            strsql = "select * from ndarticle order by id desc"
            myadapter.SelectCommand = New OleDbCommand(strsql, myconn)
            myadapter.Fill(ds, "ndarticle")
            dv = ds.Tables("ndarticle").DefaultView
            Postdg.DataSource = dv
            Postdg.DataBind()
        End Sub
        Public Sub dgrdproducts_created(ByVal s As Object, ByVal e As DataGridItemEventArgs)
            Select Case e.Item.ItemType
                Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.EditItem
                    Dim mylinkbutton As LinkButton
                    mylinkbutton = e.Item.FindControl("mydel")
                    mylinkbutton.Attributes.Add("onclick", "return confirm('确定要删除')")
            End Select
        End Sub

        Public Sub dgrdproducts_del(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
            myconn.Open()
            Dim intid As Integer = Postdg.DataKeys(e.Item.ItemIndex)
            strsql = "delete * from ndarticle where id=@id"
            Dim mycommand As OleDbCommand = New OleDbCommand(strsql, myconn)
            'mycommand.Parameters.Addwith("@id", intid)
            mycommand.Parameters.AddWithValue("@id", intid)
            mycommand.ExecuteNonQuery()
            Postdatabind()
            myconn.Close()
        End Sub
        Public Sub PagerButtonClick(ByVal sender As Object, ByVal e As System.EventArgs)
            '获得LinkButton的参数值       
            Dim arg As String = sender.commandargument
            Select Case arg
                Case "next"
                    If (Postdg.CurrentPageIndex < (Postdg.PageCount - 1)) Then
                        Postdg.CurrentPageIndex += 1
                    End If
                Case "prev"
                    If (Postdg.CurrentPageIndex > 0) Then
                        Postdg.CurrentPageIndex -= 1
                    End If
                Case "fist"
                    Postdg.CurrentPageIndex = 0
                Case "last"
                    Postdg.CurrentPageIndex = Postdg.PageCount - 1
                Case Else
                    Postdg.CurrentPageIndex = Convert.ToInt32(arg)
            End Select
            Postdatabind()
            ShowStats()
        End Sub
        Public Sub ShowStats()
            lblCurrentIndex.Text = "第 " + (Postdg.CurrentPageIndex + 1).ToString() + " 页"
            lblPageCount.Text = "总共 " + Postdg.PageCount.ToString() + " 页"
        End Sub

        Public Sub btnGo_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim PageI As Integer
            '页面直接跳转的代码
            If IsNumeric(txtGoPage.Text.Trim()) Then
                If (txtGoPage.Text.Trim() <> "") Then
                    PageI = Int32.Parse(txtGoPage.Text.Trim()) - 1
                    If (PageI >= 0 And PageI < (Postdg.PageCount)) Then
                        Postdg.CurrentPageIndex = PageI
                    End If
                End If
                Postdatabind()
                ShowStats()
            End If
        End Sub
    End Class
End Namespace
前台代码:
<%@ Page Language="VB" AutoEventWireup="false" codefile="PostManage2.aspx.vb" Inherits="aa.admin_PostManage2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <div>
    <br />
    <asp:DataGrid ID ="Postdg" runat ="server" DataKeyField ="id" AutoGenerateColumns ="false" HorizontalAlign ="center" Width ="650" BorderWidth ="1" PageSize ="30" AllowCustomPaging ="false" AllowPaging ="true" ondeletecommand="dgrdproducts_del" onitemcreated="dgrdproducts_created">
    <Columns >
    <asp:BoundColumn DataField ="username" HeaderText ="帐号"></asp:BoundColumn>
    <asp:BoundColumn DataField ="title" HeaderText ="标题"></asp:BoundColumn>
    <asp:BoundColumn DataField ="putdate" HeaderText ="日期"></asp:BoundColumn>
    <asp:TemplateColumn HeaderText ="操作">
    <ItemTemplate >
    <asp:LinkButton ID ="mydel" runat ="server" CommandName ="delete" Text ="删除"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    <PagerStyle Visible ="false" />
    </asp:DataGrid>
    <br />
    <table style="BORDER-COLLAPSE: collapse" cellSpacing="0" width="100%" border="0" align="center">
<tr>
<td align="center">
<asp:linkbutton id="btnFirst" runat="server" CommandArgument="fist" OnClick ="PagerButtonClick">首页</asp:linkbutton>  
<asp:linkbutton id="btnPrev" runat="server" Width="36px" CommandArgument="prev" OnClick ="PagerButtonClick">上一页</asp:linkbutton>  
<asp:linkbutton id="btnNext" runat="server" CommandArgument="next" OnClick ="PagerButtonClick" comm>下一页</asp:linkbutton>  
<asp:linkbutton id="btnLast" runat="server" CommandArgument="last" OnClick ="PagerButtonClick">末页</asp:linkbutton>  
<asp:label id="lblCurrentIndex" runat="server"></asp:label>/<asp:label id="lblPageCount" runat="server"></asp:label>   
跳转到 <asp:TextBox id="txtGoPage" runat="server" Width="30px" CssClass="textbox"></asp:TextBox>
<asp:Button id="btnGo" runat="server" Text="GO" CssClass="button" Width="29px" OnClick ="btnGo_Click"></asp:Button>
</td>
</tr>
</table>
    </div>
    </div>
    </form>
</body>
</html>

--------------------编程问答-------------------- 这样定义一下

Protected WithEvents Postdg As System.Web.UI.WebControls.DataGrid

其它类似 --------------------编程问答-------------------- vs2005 之前要定义的,vs2005就不用了 

Namespace aa
Public Class admin_PostManage2
        Inherits System.Web.UI.Page
        Dim connstring As String
        Dim myconn As OleDbConnection
        Dim strsql As String
        Protected WithEvents Postdg As System.Web.UI.WebControls.DataGrid
--------------------编程问答-------------------- 我用的是vc2005啊
还出现 name listitemtype is not declared 的错误 这个怎么修改啊
还有type 'linkbutton' is not defined 的错误 出错的地方是Dim mylinkbutton As LinkButton
等等...
大家别闲偶烦啊,麻烦大家了,我是新手^_^ --------------------编程问答-------------------- 自己顶下,结帖就散分啊...谢谢大家啊,继续在线等... --------------------编程问答-------------------- 顶一下 --------------------编程问答-------------------- 帮顶
--------------------编程问答-------------------- 自己顶下...
补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,