Solved

Attach Javascript Events to BoundFields in an asp:DetailsView

Posted on 2007-11-29
3
1,351 Views
Last Modified: 2013-11-05
I'm not sure if this is possible, but if I have an <asp:DetailsView />, can I attach a javascript function to the onkeyup event of the text boxes (visible while your in Insert or Edit mode)?
<html>
<head>
<script type="text/javascript">
<!--
function formatPhone( obj ) {
	var str = obj.value.replace(/[^0-9]/g, '');
 
	if( str.length < 10 ) return;
 
	var str1 = str.substring(0,3);
	var str2 = str.substring(3,6);
	var str3 = str.substring(6,10);
 
	obj.value = '(' + str1 + ') ' + str2 + '-' + str3;
}
//-->
</script>
</head>
<body>
<asp:DetailsView ID="details" runat="server" AutoGenerateRows="False" CellPadding="4"
            DataSourceID="detailisSource" DataKeyNames="ID">
<Fields>
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                    SortExpression="ID" />
                <asp:BoundField DataField="First" HeaderText="First" SortExpression="First" />
                <asp:BoundField DataField="Last" HeaderText="Last" SortExpression="Last" />
                <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" /><!-- I want to attach to the onkeyup of this BoundField -->
                <asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" />
                <asp:BoundField DataField="Street" HeaderText="Street" SortExpression="Street" />
                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                <asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
                <asp:BoundField DataField="Zip" HeaderText="Zip" SortExpression="Zip" />
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />
                <asp:HyperLinkField InsertVisible="False" NavigateUrl="Customers.aspx" ShowHeader="False"
                    Text="Return to Customer List" />
            </Fields>
</asp:DetailsView>
 
<!-- Other Page Code -->
 
</body>
</html>

Open in new window

0
Comment
Question by:netsmithcentral
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
Infinite_Recursion earned 500 total points
ID: 20377377
To achieve that, it is easier to use a TemplateField instead of a BoundField where you need to do something custom like that.
0
 
LVL 12

Author Comment

by:netsmithcentral
ID: 20377387
Can you give some code example?  I'm very new to ASP.NET and don't know about TemplateField's
0
 
LVL 7

Expert Comment

by:Infinite_Recursion
ID: 20377546
check this link for explanation on how to use them:
http://www.asp.net/learn/data-access/tutorial-13-vb.aspx
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="ProductID" DataSourceID="ObjectDataSource1" AllowPaging="True" EnableViewState="False">  <Fields>  <asp:BoundField DataField="ProductName" HeaderText="Product" SortExpression="ProductName" />  <asp:BoundField DataField="CategoryName" HeaderText="Category" ReadOnly="True" SortExpression="CategoryName" />  <asp:BoundField DataField="SupplierName" HeaderText="Supplier" ReadOnly="True" SortExpression="SupplierName" />  <asp:BoundField DataField="QuantityPerUnit" HeaderText="Qty/Unit" SortExpression="QuantityPerUnit" />  <asp:TemplateField HeaderText="Price and Inventory">  <ItemTemplate>  <asp:Label ID="Label1" runat="server" Text='<%# Eval("UnitPrice", "{0:C}") %>'></asp:Label>  <br />  <strong>  (In Stock / On Order: </strong>  <asp:Label ID="Label2" runat="server" Text='<%# Eval("UnitsInStock") %>'></asp:Label>  <strong>/</strong>  <asp:Label ID="Label3" runat="server" Text='<%# Eval("UnitsOnOrder") %>'>  </asp:Label><strong>)</strong>  </ItemTemplate>  </asp:TemplateField>  <asp:CheckBoxField DataField="Discontinued" HeaderText="Discontinued" SortExpression="Discontinued" />  </Fields> </asp:DetailsView>

Open in new window

0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question