アプリケーションコード内のクラスファイルからコントロールにアクセスするにはどうすればよいですか?アプリケーションコード内のクラスファイルからコントロールにアクセスする方法
マークアップ:にApp_Codeフォルダ内
<%@ Page Language="vb" AutoEventWireup="false" Inherits="shoppingCart1.ShoppingPage" CodeFile="ShoppingPage.aspx.vb" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>ShoppingPage</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body>
<form id="Form1" method="post" runat="server" name="Form1">
<TABLE id="tblShopping" style="FONT-SIZE:10pt;FONT-FAMILY:verdana" borderColor="black"
width="100%" cellSpacing="0" cellPadding="0" border="1" runat="server">
<tr style="FONT-SIZE:10pt;FONT-FAMILY:verdana;color:white;background-color:#336699;font-weight:bold;">
<td colspan="4">PRODUCT LIST</td>
</tr>
<tr>
***<td id="cellshoping" runat="server" colspan="4" width="100%"></td>***
</tr>
<tr>
</tr>
</TABLE>
</form>
</body>
</HTML>
ShoppingCart.vb
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Public Class ShoppingCart
Public Sub bindData()
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
Dim objDA As SqlDataAdapter
Dim myRow As SqlDataReader
Dim comd As New SqlCommand("SELECT * FROM products", con)
con.Open()
myRow = comd.ExecuteReader()
Dim strRowGen As String = ""
While myRow.Read()
strRowGen = strRowGen & "<TR>"
strRowGen = strRowGen & "<TD>" & myRow.GetValue(0) & "</TD>"
strRowGen = strRowGen & "<TD>" & myRow.GetValue(1) & "</TD>"
strRowGen = strRowGen & "<TD>" & myRow.GetValue(2) & "</TD>"
strRowGen = strRowGen & "<TD><a href='#' onclick=""javascript:document.Form1.action='ShoppingPage.aspx?Actn=Add&itemId=" & myRow.GetValue(0) & "';document.Form1.submit();"">Add To Cart</TD>"
strRowGen = strRowGen & "</TR>"
**cellshoping**.InnerHtml = strRowGen
End While
End Sub
End Class
私はcellshoping.InnerHtml
でエラーを取得するクラスからユーザーコントロールにアクセスする方法を... "cellshopingが宣言されていません"アプリコードのファイル??
ADDED ASPX CODEはBEHIND
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Namespace shoppingCart1
Partial Class ShoppingPage
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents txtNK As System.Web.UI.WebControls.TextBox
Protected WithEvents txtCF As System.Web.UI.WebControls.TextBox
Protected WithEvents txtHA As System.Web.UI.WebControls.TextBox
Protected WithEvents dtGrdProducts As System.Web.UI.WebControls.DataGrid
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'Load data by calling function bindData()
Dim sCart = New ShoppingCart
If Not Page.IsPostBack Then
cellshoping.InnerHtml = sCart.bindData()
End If
Dim strQty As Integer
Dim proId As String
Dim delId As String
delId = Request.QueryString("delItemId")
proId = Request.QueryString("itemId")
'------ Following portion act as controller where code is written as
'------ per the action from the request of the pages like Add To Cart,
'------ Update Cart & Delete Cart
strQty = 1
If Request.QueryString("Actn") <> "" Then
If Request.QueryString("Actn").Equals("Add") Then
If Request.QueryString("itemId") <> "" Then
AddToSession(proId, strQty)
Response.Redirect("./ShoppingCart.aspx")
End If
ElseIf Request.QueryString("Actn").Equals("Del") Then
If Request.QueryString("delItemId") <> "" Then
Session.Remove(delId)
Response.Redirect("./ShoppingCart.aspx")
End If
ElseIf Request.QueryString("Actn").Equals("Update") Then
If Request.QueryString("itemUpId") <> "" And Request.QueryString("quantity") <> "" Then
If IsNumeric(Request.QueryString("itemUpId")) Then
updateCart(Request.QueryString("itemUpId"), Request.QueryString("quantity"))
Response.Redirect("./ShoppingCart.aspx")
Else
Response.Redirect("./ShoppingCart.aspx")
End If
End If
End If
End If
End Sub
Private Sub AddToSession(ByVal strProduct As String, ByVal intQty As Integer)
If Not Session(strProduct) Is Nothing Then
Session.Add(strProduct, CInt(Session(strProduct)) + intQty)
Else
Session.Add(strProduct, intQty)
End If
End Sub
Private Sub updateCart(ByVal strProduct As String, ByVal qty As Integer)
If Not Session(strProduct) Is Nothing Then
Session.Add(strProduct, CInt(qty))
End If
End Sub
End Class
End Namespace
competent_techからそれを呼び出すことができますあなたはちょうどすべての尊敬の念で書いています.. – MethodMan
親切に精巧な..as @DJKRAZEは言った...私は正確に何をするか分からなかった。 –
こんにちは...親切に説明してください。私にチュートリアルを教えてください。もしあなたが自由であれば、親切に私を助けてください。 –