running32
asked on
Open a new Window and pass it the variable recordid
I have a datagrid and would like to click on the edit button when I click the edit button I would like a popup page to open, smaller than the first and ontop of the existing page. I would like to run a query when I open the page to fill in boxes from the recordId on the selected row.
I have 2 questions.
1. How can I get the new page to open, currently I have for the code in the body
<Columns>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" />
<asp:TemplateColumn>
<HeaderTemplate>
Name
</HeaderTemplate>
<ItemTemplate>
<%# Container.DataItem("name") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtName" runat="server" Text='<%# Container.DataItem("timeou t") %>' />
<asp:RequiredFieldValidato r id="rfvName" Display="Dynamic" ErrorMessage="Name is required!" ControlToValidate="txtName " runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="timein" HeaderText="Time In" ReadOnly="true" />
<asp:BoundColumn DataField="timeout" HeaderText="Time out" ReadOnly="true" />
</Columns>
serverside code
Sub dg_Update(s As Object, e As DataGridCommandEventArgs)
Dim intrecordid As Integer
Dim strtimein As String
intrecordid = dgAddressBook.DataKeys(e.I tem.ItemIn dex)
strtimein = CType(e.Item.FindControl(" txtName"), TextBox).Text
strCmd = "UPDATE Employeehours SET timeout=@timeout WHERE recordID=@recordID"
objCmd = New SqlCommand(strCmd, objConn)
objCmd.Parameters.Add("@ti meout", strtimein)
objCmd.Parameters.Add("@re cordid", intrecordid)
objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()
dgAddressBook.EditItemInde x = -1
BindData()
End Sub
2. How can I pass the recordId to the new page.
Thank you in advance. I really appreicate the help!
I have 2 questions.
1. How can I get the new page to open, currently I have for the code in the body
<Columns>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" />
<asp:TemplateColumn>
<HeaderTemplate>
Name
</HeaderTemplate>
<ItemTemplate>
<%# Container.DataItem("name")
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtName" runat="server" Text='<%# Container.DataItem("timeou
<asp:RequiredFieldValidato
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="timein" HeaderText="Time In" ReadOnly="true" />
<asp:BoundColumn DataField="timeout" HeaderText="Time out" ReadOnly="true" />
</Columns>
serverside code
Sub dg_Update(s As Object, e As DataGridCommandEventArgs)
Dim intrecordid As Integer
Dim strtimein As String
intrecordid = dgAddressBook.DataKeys(e.I
strtimein = CType(e.Item.FindControl("
strCmd = "UPDATE Employeehours SET timeout=@timeout WHERE recordID=@recordID"
objCmd = New SqlCommand(strCmd, objConn)
objCmd.Parameters.Add("@ti
objCmd.Parameters.Add("@re
objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()
dgAddressBook.EditItemInde
BindData()
End Sub
2. How can I pass the recordId to the new page.
Thank you in advance. I really appreicate the help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
Ans 1.
You can do it by DataGrid.ItemCommand Event (following link is handling same event which u want )
http://authors.aspalliance.com/aspxtreme/sys/Web/ui/webcontrols/datagridclassitemcommand.aspx
you can
Ans 2.
you can get recordId from itemcommand itselft and pass it to other page like
session("recordId") = datagrid.items...
response.write("<script language="javascript"> window.open('pagename.aspx '); </script>")
and in pagename.aspx file
you can access your recordid through session.
Regards,
NetSwap
Ans 1.
You can do it by DataGrid.ItemCommand Event (following link is handling same event which u want )
http://authors.aspalliance.com/aspxtreme/sys/Web/ui/webcontrols/datagridclassitemcommand.aspx
you can
Ans 2.
you can get recordId from itemcommand itselft and pass it to other page like
session("recordId") = datagrid.items...
response.write("<script language="javascript"> window.open('pagename.aspx
and in pagename.aspx file
you can access your recordid through session.
Regards,
NetSwap
ASKER
How can I make something llike this work.
<asp:HyperLinkColumn DataNavigateUrlField="reco rdid" DataNavigateUrlFormatStrin g="javascr ipt:window .open('pop up.aspx?re cordid={0} ', '', 'width=200,height=100');" DataTextField="recordid" HeaderText="Edit"></asp:Hy perLinkCol umn>
This code will open up a new window but the main window gives an error.
Thanks
NetSwap I get an error on response.write("<script language="javascript"> window.open('pagename.aspx '); </script>")
when I try to use your code.
<asp:HyperLinkColumn DataNavigateUrlField="reco
This code will open up a new window but the main window gives an error.
Thanks
NetSwap I get an error on response.write("<script language="javascript"> window.open('pagename.aspx
when I try to use your code.
What error do you get form the main window?
What is the code in popup.aspx?
What is the code in popup.aspx?
ASKER
the main window just has a [object] in the top left hand corner and the rest of the page is white.
I don't have any code in my popup window yet as I am not sure what to put.
Thanks
I don't have any code in my popup window yet as I am not sure what to put.
Thanks
Perhaps you could use a trivial example:
main.aspx:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!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>
<script type="text/javascript">
function popit(x) {
window.open("popup.aspx?id =" + x);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False ">
<Columns>
<asp:BoundField DataField="id" />
<asp:BoundField DataField="name" />
<asp:TemplateField >
<ItemTemplate>
<button onclick='popit(<%# DataBinder.Eval(Container, "DataItem.id") %>)'>Foo</button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
main.aspx:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
<!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>
<script type="text/javascript">
function popit(x) {
window.open("popup.aspx?id
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False
<Columns>
<asp:BoundField DataField="id" />
<asp:BoundField DataField="name" />
<asp:TemplateField >
<ItemTemplate>
<button onclick='popit(<%# DataBinder.Eval(Container,
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
main.aspx.vb:
Partial Class _Default
Inherits System.Web.UI.Page
Structure st
Public m_id As Integer
Public m_name As String
Public ReadOnly Property id() As Integer
Get
Return m_id
End Get
End Property
Public ReadOnly Property name() As String
Get
Return m_name
End Get
End Property
End Structure
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim l As New ArrayList(4)
Dim s As New st
s.m_id = 1
s.m_name = "a"
l.Add(s)
s = New st
s.m_id = 2
s.m_name = "b"
l.Add(s)
s = New st
s.m_id = 3
s.m_name = "ceci"
l.Add(s)
s = New st
s.m_id = 4
s.m_name = "dada"
l.Add(s)
GridView1.DataSource = l
GridView1.DataBind()
End Sub
End Class
Partial Class _Default
Inherits System.Web.UI.Page
Structure st
Public m_id As Integer
Public m_name As String
Public ReadOnly Property id() As Integer
Get
Return m_id
End Get
End Property
Public ReadOnly Property name() As String
Get
Return m_name
End Get
End Property
End Structure
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim l As New ArrayList(4)
Dim s As New st
s.m_id = 1
s.m_name = "a"
l.Add(s)
s = New st
s.m_id = 2
s.m_name = "b"
l.Add(s)
s = New st
s.m_id = 3
s.m_name = "ceci"
l.Add(s)
s = New st
s.m_id = 4
s.m_name = "dada"
l.Add(s)
GridView1.DataSource = l
GridView1.DataBind()
End Sub
End Class
popup.aspx:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="popup.aspx.vb" Inherits="popup" %>
<!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>
<asp:Label ID="lbName" runat=server>
</asp:Label>
</div>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="popup.aspx.vb" Inherits="popup" %>
<!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>
<asp:Label ID="lbName" runat=server>
</asp:Label>
</div>
</form>
</body>
</html>
popup.aspx.vb:
Partial Class popup
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lbName.Text = Page.Request.Params("id")
End Sub
End Class
Partial Class popup
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lbName.Text = Page.Request.Params("id")
End Sub
End Class
If you are using 2003, it is pretty much the same thing, except with a DataGrid instead of a GridView, and of course you just sub in the handler rather than declaring a "Partial Class".
What happens is that you click on the button on one of the rows, and the id is passed to popup.aspx.
In my case I just put the id in a label, but of course you could have multiple fields, and populate them all based on the value of the id.
What happens is that you click on the button on one of the rows, and the id is passed to popup.aspx.
In my case I just put the id in a label, but of course you could have multiple fields, and populate them all based on the value of the id.
ASKER
I get the error schema does not support the element asp:GridView . Thanks for helping me it would be great to get this example working
If you are using 2003, ignore the outer parts such as
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!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" >
and use whatever 2003 provides. Instead of GridView, use DataGrid.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
<!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" >
and use whatever 2003 provides. Instead of GridView, use DataGrid.
ASKER
Yes I am using 2003. I'm trying to change it now.
ASKER
It will not let me add the button I get the error schema does not support the element button. Any ideas? Thanks
For 2003 your main aspx should look like this:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx. vb" Inherits="dg.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScri pt" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script type="text/javascript">
function popit(x) {
window.open("popup.aspx?id =" + x);
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:DataGrid ID="GridView1" runat="server" AutoGenerateColumns="False ">
<Columns>
<asp:BoundColumn DataField="id" />
<asp:BoundColumn DataField="name" />
<asp:TemplateColumn>
<ItemTemplate>
<button onclick='popit(<%# DataBinder.Eval(Container, "DataItem.id") %>)'>Foo</button>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScri
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script type="text/javascript">
function popit(x) {
window.open("popup.aspx?id
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout
<form id="Form1" method="post" runat="server">
<asp:DataGrid ID="GridView1" runat="server" AutoGenerateColumns="False
<Columns>
<asp:BoundColumn DataField="id" />
<asp:BoundColumn DataField="name" />
<asp:TemplateColumn>
<ItemTemplate>
<button onclick='popit(<%# DataBinder.Eval(Container,
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>
with aspx.vb:
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
End Sub
Protected WithEvents GridView1 As System.Web.UI.WebControls. DataGrid
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclara tion As System.Object
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
Structure st
Public m_id As Integer
Public m_name As String
Public ReadOnly Property id() As Integer
Get
Return m_id
End Get
End Property
Public ReadOnly Property name() As String
Get
Return m_name
End Get
End Property
End Structure
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.Load
Dim l As New ArrayList(4)
Dim s As New st
s.m_id = 1
s.m_name = "a"
l.Add(s)
s = New st
s.m_id = 2
s.m_name = "b"
l.Add(s)
s = New st
s.m_id = 3
s.m_name = "ceci"
l.Add(s)
s = New st
s.m_id = 4
s.m_name = "dada"
l.Add(s)
GridView1.DataSource = l
GridView1.DataBind()
End Sub
End Class
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.Debugg
End Sub
Protected WithEvents GridView1 As System.Web.UI.WebControls.
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclara
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
Structure st
Public m_id As Integer
Public m_name As String
Public ReadOnly Property id() As Integer
Get
Return m_id
End Get
End Property
Public ReadOnly Property name() As String
Get
Return m_name
End Get
End Property
End Structure
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.Load
Dim l As New ArrayList(4)
Dim s As New st
s.m_id = 1
s.m_name = "a"
l.Add(s)
s = New st
s.m_id = 2
s.m_name = "b"
l.Add(s)
s = New st
s.m_id = 3
s.m_name = "ceci"
l.Add(s)
s = New st
s.m_id = 4
s.m_name = "dada"
l.Add(s)
GridView1.DataSource = l
GridView1.DataBind()
End Sub
End Class
popup.aspx:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="popup.aspx.vb" Inherits="dg.popup"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>popup</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name=vs_defaultClientScrip t 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">
<asp:Label ID="lbName" runat=server>
</asp:Label>
</form>
</body>
</html>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="popup.aspx.vb"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>popup</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name=vs_defaultClientScrip
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body MS_POSITIONING="GridLayout
<form id="Form1" method="post" runat="server">
<asp:Label ID="lbName" runat=server>
</asp:Label>
</form>
</body>
</html>
popup.aspx.vb:
Public Class popup
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclara tion As System.Object
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
Public lbName As Label
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lbName.Text = Page.Request.Params("id")
End Sub
End Class
Public Class popup
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.Debugg
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclara
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
Public lbName As Label
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lbName.Text = Page.Request.Params("id")
End Sub
End Class
ASKER
This helped point me in the right direction. thanks
<button onclick='window.open("popu