Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Attach Javascript Events to BoundFields in an asp:DetailsView

Posted on 2007-11-29
3
Medium Priority
?
1,366 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

972 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