Click here to Skip to main content
15,887,381 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Friends,

I am using VS 2008.I have a gridView with template column.I have a textbox control in template column.When It is assigned with zero figures(0.00).When we click and type 1 in that field, 10.00 is coming.That means zero before decimal stays when typing in that field.How to avoid this and it should display 1.00

What I have tried:

tried to mask in the template column
Posted
Updated 1-Aug-17 0:15am
Comments
Karthik_Mahalingam 1-Aug-17 4:19am    
show the code.

1 solution

You'll probably need to do something like this using jQuery (or the javascript framework of your choice). If you have textboxes similar to these:
<input type="text" class="decimal" value="0.00"/>

Then you can add a couple of event handlers for when users enter and exit these textboxes:
$('input.decimal').focusin(function() {
	if ($(this).val() === '0.00') {
  	$(this).val('');
  }
});
$('input.decimal').focusout(function() {
  var value = parseFloat($(this).val());
	if (isNaN(value)) {
  	$(this).val('0.00');
  } else {
  	$(this).val(value.toFixed(2));
  }
});

You'll probably need to add some extra code to cover pasting into the text boxes. You can take a look at an example on jsfiddle[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900