<script type="text/javascript">
function OpenPopup() {
window.open("PurchaseRec.aspx","List","scrollbars=no,resizable=no,width=500,height=400");
return false;
}
</script>
หน้าที่เป็น ป๊อปอัพดีไซน์ Code (VB.NET)
<script language="javascript">
function GetRowValue(val)
{
// hardcoded value used to minimize the code.
// ControlID can instead be passed as query string to the popup window
window.opener.document.getElementById("txtPur_id").value = val;
window.close();
}
</script>
หน้าโค้ดข้างใน Popup ค่ะ Code (VB.NET)
Imports System.Data
Imports System.Data.SqlClient
Partial Public Class PurchaseRec
Inherits System.Web.UI.Page
Dim ConnStr As String = "server=(local);database=DB_CMS;uid=AdminCMS;password=qaz123"
Dim Conn As New SqlConnection(ConnStr)
Dim Myda As New SqlDataAdapter("Select * From Tl_Stock", Conn)
Dim CmdStock, CmdCompany, CmdBuy, Cmdrecieve As SqlCommand
Dim Ds As New DataSet
Dim sql As String
Dim Cmd As SqlCommand
Dim Ad As SqlDataAdapter
Dim dview As DataView
Sub showdatagrid()
sql = "SELECT Tl_Purchase.St_id, Tl_Stock.St_name,Tl_Stock.St_Price, Tl_Purchase.Pur_amount ,Tl_Purchase.Pur_id FROM Tl_Purchase INNER JOIN Tl_Stock ON Tl_Purchase.St_id = Tl_Stock.St_Id order by Tl_Purchase.Pur_id "
'//กำหนด Sqlสำหรับอ่านข้อมูล
Ad = New SqlDataAdapter(Sql, Conn) '///ประมวลผลคำสั่งอ่านข้อมูล
Ad.Fill(Ds, "Table1") '///นำข้อมูลที่อ่านข้อมูลได้ไปให้กับDsแบบดาต้าเซต
dview = Ds.Tables("Table1").DefaultView '///นำข้อมูลในDsแบบดาต้าเซตไปให้ดาต้าวิว
sql = "SELECT Tl_Purchase.St_id, Tl_Stock.St_name,Tl_Stock.St_Price, Tl_Purchase.Pur_amount ,Tl_Purchase.Pur_id FROM Tl_Purchase INNER JOIN Tl_Stock ON Tl_Purchase.St_id = Tl_Stock.St_Id order by Tl_Purchase.Pur_id"
Ad = New SqlDataAdapter(sql, Conn)
Ad.Fill(Ds, "MyData")
GridView1.DataSource = Ds.Tables("MyData")
GridView1.DataBind()
BtnCloseDisplay.Visible = True
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
showdatagrid()
End Sub
Protected Sub BtnCloseDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCloseDisplay.Click
Response.Redirect("Add_Recieve.aspx")
End Sub
Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
'assuming that the required value column is the second column in gridview
DirectCast(e.Row.FindControl("LinkButton2"), LinkButton).Attributes.Add("onclick", "javascript:GetRowValue('" & e.Row.Cells(0).Text & "')")
End If
End Sub
End Class