Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > ASP.NET > ASP.NET DataList Control > ASP.NET DataList Control - ItemCommand VS .NET 2003 (FX 1.1)



Clound SSD Virtual Server

ASP.NET DataList Control - ItemCommand VS .NET 2003 (FX 1.1)

ASP.NET DataList Control - ItemCommand (Visual Studio .NET 2003) ตัวอย่างนี้จะเป็นการใช้ ItemCommand ซึ่งเขียนบน Visual Studio .NET 2003 และ Framework 1.1 ในรูปแบบของ Code Behind

Language Code : VB.NET || C#

Framework : 1.1


DataListItemCommand.aspx

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="DataListItemCommand.aspx.vb" Inherits="MyDotNet.DataListItemCommand"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
	<HEAD>
		<title>ThaiCreate.Com ASP.NET - DataList</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" enctype="multipart/form-data">
			<asp:DataList id="myDataList" runat="server" RepeatColumns="2" cellpadding="2" cellspacing="2"
				borderstyle="inset">
				<HeaderTemplate>
					<b>My Category</b><br />
				</HeaderTemplate>
				<ItemTemplate>
					<div style="width:100px" align="center">
						<asp:Image id="imgPicture" runat="server"></asp:Image>
						<br />
						<asp:HyperLink id="hplCategory" runat="server"></asp:HyperLink>
						<br />
						<asp:LinkButton id="lnkEdit" runat="server" CommandName="Edit">Edit</asp:LinkButton>
					</div>
				</ItemTemplate>
				<EditItemTemplate>
					<asp:Label id="lblCateID" runat="server" Visible = "False" text='<%#Container.DataItem("CategoryID")%>'>
					</asp:Label>
					<asp:TextBox id="txtCategory" runat="server" text='<%#Container.DataItem("CategoryName")%>'>
					</asp:TextBox><br />
					<input id="filPicture" type="file" runat="server" NAME="filPicture"><br />
					&nbsp;
					<asp:LinkButton id="lnkUpdate" runat="server" CommandName="Update">Update</asp:LinkButton>
					<asp:LinkButton id="lnkCancel" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
				</EditItemTemplate>
			</asp:DataList>
		</form>
	</body>
</html>



DataListItemCommand.aspx.vb

Imports System.Data
Imports System.Data.OleDb
Public Class DataListItemCommand
    Inherits System.Web.UI.Page
    Dim objConn As OleDbConnection
    Dim objCmd As OleDbCommand
    Dim strSQL As String

#Region " Web Form Designer Generated Code "

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim strConnString As String
        strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database/mydatabase.mdb") & ";"
        objConn = New OleDbConnection(strConnString)
        objConn.Open()

        If Not Page.IsPostBack() Then
            BindData()
        End If
    End Sub

    Protected Sub BindData()
        strSQL = "SELECT * FROM category"

        Dim dtReader As OleDbDataReader
        objCmd = New OleDbCommand(strSQL, objConn)
        dtReader = objCmd.ExecuteReader()

        '*** BindData to DataList ***'
        myDataList.DataSource = dtReader
        myDataList.DataBind()

        dtReader.Close()
        dtReader = Nothing

    End Sub

    Private Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Unload
        objConn.Close()
        objConn = Nothing
    End Sub

    Private Sub myDataList_CancelCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles myDataList.CancelCommand
        myDataList.EditItemIndex = -1
        BindData()
    End Sub

    Private Sub myDataList_EditCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles myDataList.EditCommand
        myDataList.EditItemIndex = e.Item.ItemIndex
        BindData()
    End Sub

    Private Sub myDataList_UpdateCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles myDataList.UpdateCommand
        '*** CategoryID ***'
        Dim lblCateID As Label = CType(e.Item.FindControl("lblCateID"), Label)
        '*** txtCategory ***'
        Dim txtCategory As TextBox = CType(e.Item.FindControl("txtCategory"), TextBox)


        strSQL = "UPDATE category SET CategoryName = '" & txtCategory.Text & "' " & _
        " WHERE CategoryID = " & lblCateID.Text & " "
        objCmd = New OleDbCommand(strSQL, objConn)
        objCmd.ExecuteNonQuery()

        '*** If Select File Upload ***'
        Dim filPicture As HtmlInputFile = CType(e.Item.FindControl("filPicture"), HtmlInputFile)
        Dim strFileName As String
        If Trim(filPicture.PostedFile.FileName) <> "" Then
            strFileName = System.IO.Path.GetFileName(filPicture.Value)
            filPicture.PostedFile.SaveAs(Server.MapPath("images/" & strFileName))
            strSQL = "UPDATE category SET Picture = 'images/" & strFileName & "' " & _
            " WHERE CategoryID = " & lblCateID.Text & " "
            objCmd = New OleDbCommand(strSQL, objConn)
            objCmd.ExecuteNonQuery()
        End If

        myDataList.EditItemIndex = -1
        BindData()
    End Sub

    Private Sub myDataList_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs) Handles myDataList.ItemDataBound
        '*** Image ***'
        Dim img As System.Web.UI.WebControls.Image = CType(e.Item.FindControl("imgPicture"), System.Web.UI.WebControls.Image)
        If Not IsNothing(img) Then
            img.ImageUrl = e.Item.DataItem("Picture")
            'img.Attributes.Add("OnClick","window.location='https://www.thaicreate.com?CateID="&e.Item.DataItem("CategoryID")&"'")
            'img.Style.Add("cursor","hand")
        End If

        '*** HyperLink ***'		
        Dim hplCate As HyperLink = CType(e.Item.FindControl("hplCategory"), HyperLink)
        If Not IsNothing(hplCate) Then
            hplCate.Text = e.Item.DataItem("CategoryName")
            hplCate.ToolTip = e.Item.DataItem("CategoryName")
            hplCate.NavigateUrl = "https://www.thaicreate.com?CateID=" & e.Item.DataItem("CategoryID")
        End If
    End Sub
End Class









Screenshot

ASP.NET DataList Control

ASP.NET DataList Control

   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2008-11-15 07:08:09 / 2017-03-28 21:29:09
  Download : Download  ASP.NET DataList Control - ItemCommand VS .NET 2003 (FX 1.1)
 Sponsored Links / Related

 
ASP.NET DataList Control
Rating :

 
ASP.NET DataList Control - DataBind
Rating :

 
ASP.NET DataList Control - Repeat Multiple Columns
Rating :

 
ASP.NET DataList Control - DataBound
Rating :

 
ASP.NET DataList Control - DataSet,DataTable,TableRows
Rating :

 
ASP.NET DataList Control - FindControl
Rating :

 
ASP.NET DataList Control - ItemCommand
Rating :

 
ASP.NET DataList Control - XML
Rating :

 
ASP.NET DataList Control - AccessDataSource
Rating :

 
ASP.NET DataList Control - VS .NET 2003 (FX 1.1)
Rating :

 
ASP.NET DataList Control - VS 2005,2008,2010 (FX 2.0,3.5,4.0)
Rating :

 
ASP.NET DataList Control - ItemCommand VS 2005,2008,2010 (FX 2.0,3.5,4.0)
Rating :

 
ASP.NET DataList Control - Microsoft Access (.mdb) - System.Data.OleDb
Rating :

 
ASP.NET DataList Control - SQL Server 2000,2005,2008 - System.Data.SqlClient
Rating :

 
ASP.NET DataList Control - MySQL Database - MySql.Data.MySqlClient
Rating :

 
ASP.NET DataList Control - Oracle Database - System.Data.OracleClient
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่