Solved

Attach Javascript Events to BoundFields in an asp:DetailsView

Posted on 2007-11-29
3
1,332 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
  • 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now