p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

aspx thread: Setting focus on a textbox in a DataList in an EditItemTemplate


Message #1 by "Oliver, Wells" <WOliver@l...> on Thu, 18 Jul 2002 13:52:00 -0700
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C22E9C.F6C5CFD0
Content-Type: text/plain;
	charset="iso-8859-1"

How can this be done? I'd like the focus to be put on a textbox when the
user clicks on 'Edit'.

Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com 

Message #2 by "Mingkun Goh" <mangokun@h...> on Sat, 20 Jul 2002 07:44:51
Previous message:
How can this be done? I'd like the focus to be put on a textbox when the
user clicks on 'Edit'.

Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com 



My message:

In the aspx/html page,
By making use of a bit of JavaScript, I will have a function that loop 
through all the elements in the form to look for the TextBox. When found, 
the TextBox will be focused, and the loop is terminated.

In the code-behind page,
When the DataGrid1_ItemCommand event is triggered because the user has 
clicked on your Edit button in the DataGrid, I will insert a client-side 
JavaScript that just call the JavaScript function (mentioned above), 
passing it a parameter (which is the id of the TextBox).


Here are the source for my sample page that demostrate this.

[WebForm1.aspx]

<%@ Page Language="vb" AutoEventWireup="false" 
Codebehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
	<HEAD>
		<title>Setting focus to a TextBox in a DataGrid</title>
		<meta name="GENERATOR" content="Microsoft Visual 
Studio.NET 7.0">
		<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" 
content="http://schemas.microsoft.com/intellisense/ie5">
		
		<script language="JavaScript">
<!--
function findTextBox(controlid) {
  var elem
  for(i=0;i<document.forms[0].elements.length;i++) {
    elem=document.forms[0].elements[i]
    if (elem.name.indexOf(controlid)!=-1) {
      elem.focus() //set the focus to the control
      return true //stops the loop
    }
  }
}

//-->
</script>

	</HEAD>
	<body MS_POSITIONING="GridLayout">
		<form id="Form1" method="post" runat="server">
			<asp:DataGrid id=DataGrid1 style="Z-INDEX: 101; 
LEFT: 13px; POSITION: absolute; TOP: 42px" runat="server" DataSource="<%# 
DataSet11 %>" DataKeyField="CustomerID" DataMember="Customers" 
AutoGenerateColumns="False">
				<Columns>
					<asp:TemplateColumn 
HeaderText="CustomerID">
						<ItemTemplate>
							<asp:Label 
runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CustomerID") 
%>'>
							</asp:Label>
						</ItemTemplate>
					</asp:TemplateColumn>
					<asp:TemplateColumn 
HeaderText="ContactName">
						<ItemTemplate>
							<asp:Label 
runat="server" Text='<%# DataBinder.Eval
(Container, "DataItem.ContactName") %>'>
							</asp:Label>
						</ItemTemplate>
					</asp:TemplateColumn>
					<asp:TemplateColumn 
HeaderText="ContactTitle">
						<ItemTemplate>
							<asp:Label 
id=Label2 runat="server" Text='<%# DataBinder.Eval
(Container, "DataItem.ContactTitle") %>'>
							</asp:Label>
						</ItemTemplate>
						<EditItemTemplate>
							<asp:TextBox 
id=txtEdit1 runat="server" Text='<%# DataBinder.Eval
(Container, "DataItem.ContactTitle") %>'>
							</asp:TextBox>
						</EditItemTemplate>
					</asp:TemplateColumn>
					<asp:TemplateColumn>
						<ItemTemplate>
							<asp:Button 
runat="server" Text="Edit" CommandName="Edit" 
CausesValidation="false"></asp:Button>
						</ItemTemplate>
						<EditItemTemplate>
							<asp:Button 
runat="server" Text="Done" CommandName="Done" 
CausesValidation="false"></asp:Button>
						</EditItemTemplate>
					</asp:TemplateColumn>
				</Columns>
			</asp:DataGrid>
		</form>
	</body>
</HTML>




[WebForm1.aspx.vb]

Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected WithEvents SqlSelectCommand1 As 
System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlInsertCommand1 As 
System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlUpdateCommand1 As 
System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlDeleteCommand1 As 
System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlConnection1 As 
System.Data.SqlClient.SqlConnection
    Protected WithEvents SqlDataAdapter1 As 
System.Data.SqlClient.SqlDataAdapter
    Protected WithEvents DataSet11 As WebApplication1.DataSet1
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub 
InitializeComponent()
        Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand()
        Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection()
        Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand()
        Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand()
        Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand()
        Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter()
        Me.DataSet11 = New WebApplication1.DataSet1()
        CType(Me.DataSet11, 
System.ComponentModel.ISupportInitialize).BeginInit()
        '
        'SqlSelectCommand1
        '
        Me.SqlSelectCommand1.CommandText = "SELECT CustomerID, 
CompanyName, ContactName, ContactTitle, Address, City, Region," & _
        " PostalCode, Country, Phone, Fax FROM Customers"
        Me.SqlSelectCommand1.Connection = Me.SqlConnection1
        '
        'SqlConnection1
        '
        Me.SqlConnection1.ConnectionString = "data 
source=localhost;initial catalog=Northwind;integrated 
security=SSPI;persist " & _
        "security info=False;workstation id=KUN;packet size=4096"
        '
        'SqlInsertCommand1
        '
        Me.SqlInsertCommand1.CommandText = "INSERT INTO Customers
(CustomerID, CompanyName, ContactName, ContactTitle, Address" & _
        ", City, Region, PostalCode, Country, Phone, Fax) VALUES 
(@CustomerID, @CompanyNa" & _
        "me, @ContactName, @ContactTitle, @Address, @City, @Region, 
@PostalCode, @Country" & _
        ", @Phone, @Fax); SELECT CustomerID, CompanyName, ContactName, 
ContactTitle, Addr" & _
        "ess, City, Region, PostalCode, Country, Phone, Fax FROM Customers 
WHERE (Custome" & _
        "rID = @CustomerID)"
        Me.SqlInsertCommand1.Connection = Me.SqlConnection1
        Me.SqlInsertCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@CustomerID", 
System.Data.SqlDbType.NVarChar, 5, "CustomerID"))
        Me.SqlInsertCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@CompanyName", 
System.Data.SqlDbType.NVarChar, 40, "CompanyName"))
        Me.SqlInsertCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@ContactName", 
System.Data.SqlDbType.NVarChar, 30, "ContactName"))
        Me.SqlInsertCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@ContactTitle", 
System.Data.SqlDbType.NVarChar, 30, "ContactTitle"))
        Me.SqlInsertCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Address", 
System.Data.SqlDbType.NVarChar, 60, "Address"))
        Me.SqlInsertCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@City", 
System.Data.SqlDbType.NVarChar, 15, "City"))
        Me.SqlInsertCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Region", 
System.Data.SqlDbType.NVarChar, 15, "Region"))
        Me.SqlInsertCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@PostalCode", 
System.Data.SqlDbType.NVarChar, 10, "PostalCode"))
        Me.SqlInsertCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Country", 
System.Data.SqlDbType.NVarChar, 15, "Country"))
        Me.SqlInsertCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Phone", 
System.Data.SqlDbType.NVarChar, 24, "Phone"))
        Me.SqlInsertCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Fax", System.Data.SqlDbType.NVarChar, 
24, "Fax"))
        '
        'SqlUpdateCommand1
        '
        Me.SqlUpdateCommand1.CommandText = "UPDATE Customers SET 
CustomerID = @CustomerID, CompanyName = @CompanyName, Contac" & _
        "tName = @ContactName, ContactTitle = @ContactTitle, Address = 
@Address, City = @" & _
        "City, Region = @Region, PostalCode = @PostalCode, Country = 
@Country, Phone = @P" & _
        "hone, Fax = @Fax WHERE (CustomerID = @Original_CustomerID) AND 
(Address = @Origi" & _
        "nal_Address OR @Original_Address IS NULL AND Address IS NULL) AND 
(City = @Origi" & _
        "nal_City OR @Original_City IS NULL AND City IS NULL) AND 
(CompanyName = @Origina" & _
        "l_CompanyName) AND (ContactName = @Original_ContactName OR 
@Original_ContactName" & _
        " IS NULL AND ContactName IS NULL) AND (ContactTitle = 
@Original_ContactTitle OR " & _
        "@Original_ContactTitle IS NULL AND ContactTitle IS NULL) AND 
(Country = @Origina" & _
        "l_Country OR @Original_Country IS NULL AND Country IS NULL) AND 
(Fax = @Original" & _
        "_Fax OR @Original_Fax IS NULL AND Fax IS NULL) AND (Phone = 
@Original_Phone OR @" & _
        "Original_Phone IS NULL AND Phone IS NULL) AND (PostalCode = 
@Original_PostalCode" & _
        " OR @Original_PostalCode IS NULL AND PostalCode IS NULL) AND 
(Region = @Original" & _
        "_Region OR @Original_Region IS NULL AND Region IS NULL); SELECT 
CustomerID, Comp" & _
        "anyName, ContactName, ContactTitle, Address, City, Region, 
PostalCode, Country, " & _
        "Phone, Fax FROM Customers WHERE (CustomerID = @CustomerID)"
        Me.SqlUpdateCommand1.Connection = Me.SqlConnection1
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@CustomerID", 
System.Data.SqlDbType.NVarChar, 5, "CustomerID"))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@CompanyName", 
System.Data.SqlDbType.NVarChar, 40, "CompanyName"))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@ContactName", 
System.Data.SqlDbType.NVarChar, 30, "ContactName"))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@ContactTitle", 
System.Data.SqlDbType.NVarChar, 30, "ContactTitle"))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Address", 
System.Data.SqlDbType.NVarChar, 60, "Address"))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@City", 
System.Data.SqlDbType.NVarChar, 15, "City"))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Region", 
System.Data.SqlDbType.NVarChar, 15, "Region"))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@PostalCode", 
System.Data.SqlDbType.NVarChar, 10, "PostalCode"))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Country", 
System.Data.SqlDbType.NVarChar, 15, "Country"))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Phone", 
System.Data.SqlDbType.NVarChar, 24, "Phone"))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Fax", System.Data.SqlDbType.NVarChar, 
24, "Fax"))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_CustomerID", 
System.Data.SqlDbType.NVarChar, 5, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "CustomerID", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_Address", 
System.Data.SqlDbType.NVarChar, 60, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "Address", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_City", 
System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "City", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_CompanyName", 
System.Data.SqlDbType.NVarChar, 40, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "CompanyName", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_ContactName", 
System.Data.SqlDbType.NVarChar, 30, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "ContactName", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_ContactTitle", 
System.Data.SqlDbType.NVarChar, 30, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "ContactTitle", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_Country", 
System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "Country", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_Fax", 
System.Data.SqlDbType.NVarChar, 24, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "Fax", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_Phone", 
System.Data.SqlDbType.NVarChar, 24, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "Phone", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_PostalCode", 
System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "PostalCode", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_Region", 
System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "Region", 
System.Data.DataRowVersion.Original, Nothing))
        '
        'SqlDeleteCommand1
        '
        Me.SqlDeleteCommand1.CommandText = "DELETE FROM Customers WHERE 
(CustomerID = @Original_CustomerID) AND (Address = @O" & _
        "riginal_Address OR @Original_Address IS NULL AND Address IS NULL) 
AND (City = @O" & _
        "riginal_City OR @Original_City IS NULL AND City IS NULL) AND 
(CompanyName = @Ori" & _
        "ginal_CompanyName) AND (ContactName = @Original_ContactName OR 
@Original_Contact" & _
        "Name IS NULL AND ContactName IS NULL) AND (ContactTitle = 
@Original_ContactTitle" & _
        " OR @Original_ContactTitle IS NULL AND ContactTitle IS NULL) AND 
(Country = @Ori" & _
        "ginal_Country OR @Original_Country IS NULL AND Country IS NULL) 
AND (Fax = @Orig" & _
        "inal_Fax OR @Original_Fax IS NULL AND Fax IS NULL) AND (Phone = 
@Original_Phone " & _
        "OR @Original_Phone IS NULL AND Phone IS NULL) AND (PostalCode = 
@Original_Postal" & _
        "Code OR @Original_PostalCode IS NULL AND PostalCode IS NULL) AND 
(Region = @Orig" & _
        "inal_Region OR @Original_Region IS NULL AND Region IS NULL)"
        Me.SqlDeleteCommand1.Connection = Me.SqlConnection1
        Me.SqlDeleteCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_CustomerID", 
System.Data.SqlDbType.NVarChar, 5, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "CustomerID", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_Address", 
System.Data.SqlDbType.NVarChar, 60, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "Address", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_City", 
System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "City", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_CompanyName", 
System.Data.SqlDbType.NVarChar, 40, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "CompanyName", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_ContactName", 
System.Data.SqlDbType.NVarChar, 30, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "ContactName", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_ContactTitle", 
System.Data.SqlDbType.NVarChar, 30, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "ContactTitle", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_Country", 
System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "Country", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_Fax", 
System.Data.SqlDbType.NVarChar, 24, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "Fax", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_Phone", 
System.Data.SqlDbType.NVarChar, 24, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "Phone", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_PostalCode", 
System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "PostalCode", 
System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New 
System.Data.SqlClient.SqlParameter("@Original_Region", 
System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, 
False, CType(0, Byte), CType(0, Byte), "Region", 
System.Data.DataRowVersion.Original, Nothing))
        '
        'SqlDataAdapter1
        '
        Me.SqlDataAdapter1.DeleteCommand = Me.SqlDeleteCommand1
        Me.SqlDataAdapter1.InsertCommand = Me.SqlInsertCommand1
        Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
        Me.SqlDataAdapter1.TableMappings.AddRange(New 
System.Data.Common.DataTableMapping() {New 
System.Data.Common.DataTableMapping("Table", "Customers", New 
System.Data.Common.DataColumnMapping() {New 
System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"), New 
System.Data.Common.DataColumnMapping("CompanyName", "CompanyName"), New 
System.Data.Common.DataColumnMapping("ContactName", "ContactName"), New 
System.Data.Common.DataColumnMapping("ContactTitle", "ContactTitle"), New 
System.Data.Common.DataColumnMapping("Address", "Address"), New 
System.Data.Common.DataColumnMapping("City", "City"), New 
System.Data.Common.DataColumnMapping("Region", "Region"), New 
System.Data.Common.DataColumnMapping("PostalCode", "PostalCode"), New 
System.Data.Common.DataColumnMapping("Country", "Country"), New 
System.Data.Common.DataColumnMapping("Phone", "Phone"), New 
System.Data.Common.DataColumnMapping("Fax", "Fax")})})
        Me.SqlDataAdapter1.UpdateCommand = Me.SqlUpdateCommand1
        '
        'DataSet11
        '
        Me.DataSet11.DataSetName = "DataSet1"
        Me.DataSet11.Locale = New System.Globalization.CultureInfo("en-US")
        Me.DataSet11.Namespace = "http://www.tempuri.org/DataSet1.xsd"
        CType(Me.DataSet11, 
System.ComponentModel.ISupportInitialize).EndInit()

    End Sub

    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
        If Not Page.IsPostBack Then
            SqlDataAdapter1.Fill(DataSet11)
            DataGrid1.DataBind()
        End If
    End Sub

    Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As 
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles 
DataGrid1.ItemCommand
        If e.CommandName = "Edit" Then
            DataGrid1.EditItemIndex = e.Item.ItemIndex

            SqlDataAdapter1.Fill(DataSet11)
            DataGrid1.DataBind()

            'Form the script that is to be registered at client side.
            Dim scriptString As String = "<script language=JavaScript>"
            scriptString += "findTextBox('txtEdit1')"
            scriptString += "</script>"

            If Not IsStartupScriptRegistered("Startup") Then
                RegisterStartupScript("Startup", scriptString)
            End If

        ElseIf e.CommandName = "Done" Then
            DataGrid1.EditItemIndex = -1

            SqlDataAdapter1.Fill(DataSet11)
            DataGrid1.DataBind()
        End If
    End Sub
End Class
Message #3 by "Mingkun Goh" <mangokun@h...> on Sat, 20 Jul 2002 09:01:22
You can also use this javascript function instead:

<script language="JavaScript">
<!--
function getTextBox(controlid) {
  var elem
  for(i=0;i<document.forms[0].elements.length;i++) {
    elem=document.forms[0].elements[i]
    if (elem.name.indexOf(controlid)!=-1) {
      return elem
    }
  }
}

//-->
</script>


then in your code-behind,

            'Form the script that is to be registered at client side.
            Dim scriptString As String = "<script language=JavaScript>"
            scriptString += "getTextBox('txtEdit1').focus()"
            scriptString += "</script>"

  Return to Index