Pinch Zoom - Getting touch coordinates - windows

I am developing a Windows 8 app using WinJS. I am trying to get the touch coordinates for pinch and zoom. I have implemented the gesture manipulation handlers via Windows.UI.Input.GestureRecognizer. I am triggering my pinch and zoom logic when for the "manipulationupdated" event, event.delta.scale is not 1. When manipulation happens inside the "manipulationupdated" event object I find coordinates of only 1 position. How do I calculate both the finger touch coordinates from this information?
Also how do I know which touch coordinate the position belong to? I find the position repeated multiple times inside the event object - at event.position and event.detail[0].position
What I am trying to achieve is performing pinch and zoom in a chart(much like a map). Kindly help me out with these questions.

public class PZBehavior : Behavior
{
bool _isDragging;
bool _isPinching;
Point _ptPinchPositionStart;
private Image _imgZoom;
private ScaleTransform _scaleTransform;
private RotateTransform _rotateTransform;
private TranslateTransform _translateTransform;
private MatrixTransform _previousTransform;
private TransformGroup _parentGroup;
private TransformGroup _currentTransform;
protected override void OnAttached()
{
_imgZoom = AssociatedObject;
_imgZoom.RenderTransform = BuildTrasnformGroup();
var listener = GestureService.GetGestureListener(AssociatedObject);
listener.DragStarted += DragStarted;
listener.DragDelta += DragDelta;
listener.DragCompleted += DragCompleted;
listener.PinchStarted += PinchStarted;
listener.PinchDelta += PinchDelta;
listener.PinchCompleted += PinchCompleted;
}
private TransformGroup BuildTrasnformGroup()
{
_parentGroup = new TransformGroup();
_currentTransform = new TransformGroup();
_previousTransform = new MatrixTransform();
_scaleTransform = new ScaleTransform();
_rotateTransform = new RotateTransform();
_translateTransform = new TranslateTransform();
_currentTransform.Children.Add(_scaleTransform);
_currentTransform.Children.Add(_rotateTransform);
_currentTransform.Children.Add(_translateTransform);
_parentGroup.Children.Add(_previousTransform);
_parentGroup.Children.Add(_currentTransform);
return _parentGroup;
}
void PinchCompleted(object sender, PinchGestureEventArgs e)
{
if (_isPinching)
{
TransferTransforms();
_isPinching = false;
}
}
void PinchDelta(object sender, PinchGestureEventArgs e)
{
if (_isPinching)
{
// Set scaling
_scaleTransform.ScaleX = e.DistanceRatio;
_scaleTransform.ScaleY = e.DistanceRatio;
// Optionally set rotation
_rotateTransform.Angle = e.TotalAngleDelta;
// Set translation
Point ptPinchPosition = new Point(0,0);
_translateTransform.X = ptPinchPosition.X - _ptPinchPositionStart.X;
_translateTransform.Y = ptPinchPosition.Y - _ptPinchPositionStart.Y;
}
}
void PinchStarted(object sender, PinchStartedGestureEventArgs e)
{
_isPinching = e.OriginalSource == _imgZoom;
if (_isPinching)
{
// Set transform centers
Point ptPinchCenter = e.GetPosition(_imgZoom);
ptPinchCenter = _previousTransform.Transform(ptPinchCenter);
_scaleTransform.CenterX = ptPinchCenter.X;
_scaleTransform.CenterY = ptPinchCenter.Y;
_rotateTransform.CenterX = ptPinchCenter.X;
_rotateTransform.CenterY = ptPinchCenter.Y;
_ptPinchPositionStart = new Point(0,0);
}
}
void DragCompleted(object sender, DragCompletedGestureEventArgs e)
{
if (_isDragging)
{
TransferTransforms();
_isDragging = false;
}
}
void DragDelta(object sender, DragDeltaGestureEventArgs e)
{
if (_isDragging)
{
_translateTransform.X += e.HorizontalChange;
_translateTransform.Y += e.VerticalChange;
}
}
void DragStarted(object sender, DragStartedGestureEventArgs e)
{
_isDragging = e.OriginalSource == _imgZoom;
}
void TransferTransforms()
{
_previousTransform.Matrix = Multiply(_previousTransform.Matrix, _currentTransform.Value);
// Set current transforms to default values
_scaleTransform.ScaleX = _scaleTransform.ScaleY = 1;
_scaleTransform.CenterX = _scaleTransform.CenterY = 0;
_rotateTransform.Angle = 0;
_rotateTransform.CenterX = _rotateTransform.CenterY = 0;
_translateTransform.X = _translateTransform.Y = 0;
}
Matrix Multiply(Matrix a, Matrix b)
{
return new Matrix(a.M11 * b.M11 + a.M12 * b.M21,
a.M11 * b.M12 + a.M12 * b.M22,
a.M21 * b.M11 + a.M22 * b.M21,
a.M21 * b.M12 + a.M22 * b.M22,
a.OffsetX * b.M11 + a.OffsetY * b.M21 + b.OffsetX,
a.OffsetX * b.M12 + a.OffsetY * b.M22 + b.OffsetY);
}
}

Related

Camera timer animation on UWP

I am developing an UWP application, and one of my page is actually for user to take photo of them. In the page, I have timers for user to select before they take picture.
However, I wish to have a timer shown, counting down in the camera screen, so that the user know how much time is left for them to prepare, before the picture is taken.
Any idea on how I can do that? Thank you!
Just in case it is needed, here is my codes for the timers and the take picture buttons:
private async void PhotoButton_Click(object sender, RoutedEventArgs e)
{
//If preview is not running, no preview frames can be acquired
if (!_isPreviewing) return;
await Task.Delay(TimeSpan.FromSeconds(_seconds));
await TakePhotoAsync();
await GetPreviewFrameAsSoftwareBitmapAsync();
PreviewFrameBackground.Visibility = Visibility.Visible;
}
private void Timer_3sec_Click(object sender, RoutedEventArgs e)
{
Timer_5sec.Opacity = 0.2;
Timer_7sec.Opacity = 0.2;
Timer_3sec.Opacity = 1.0;
_seconds = 3;
}
private void Timer_5sec_Click(object sender, RoutedEventArgs e)
{
Timer_3sec.Opacity = 0.2;
Timer_7sec.Opacity = 0.2;
Timer_5sec.Opacity = 1.0;
_seconds = 5;
}
private void Timer_7sec_Click(object sender, RoutedEventArgs e)
{
Timer_3sec.Opacity = 0.2;
Timer_5sec.Opacity = 0.2;
Timer_7sec.Opacity = 1.0;
_seconds = 7;
}
You can use a DispatcherTimer to solve your problem.
Here a little code sample how you can do that (The sample dont show how to take the capture or to show the remaining seconds, just to calculate them!)
Class-Parameters:
private int _startTime;
private DispatcherTimer _timer = new DispatcherTimer();
Methods:
private void StartTimer()
{
_timer.Interval = TimeSpan.FromMilliseconds(500);
_timer.Tick += Timer_Tick;
_startTime = Environment.TickCount;
_timer.Start();
}
private void Timer_Tick(object sender, object e)
{
var remainingSeconds = _seconds - TimeSpan.FromMilliseconds(Environment.TickCount - _startTime).Seconds;
if(remainingSeconds <= 0)
{
_timer.Stop();
_timer.Tick -= Timer_Tick;
timerText.Text = "0 Seconds";
//Capture Image
} else
{
timerText.Text = "" + remainingSeconds + " Seconds";
}
}
You need to call the StartTimer-Method in you Click-Methods, after setting the _seconds.

windows phone application button content

I've got incredibly weird problem. I'm making memo game app on windows phone. When I click 2 buttons and if they have the same content they should collapse. Problem is that even if they have the same content for example 1 it shows me that this statement is false! Like 1 was not equal 1.
Here's the code:
public partial class Memo : PhoneApplicationPage
{
private int points = 100;
private string[] numbers={"a","a"};
private Button selected_button;
public Memo()
{
InitializeComponent();
button1.Content = numbers[0];
button2.Content = numbers[1];
}
private void button1_Click(object sender, RoutedEventArgs e)
{
if (selected_button != null)
{
PageTitle.Text = "" + selected_button.Content + " " + button1.Content;
if (selected_button.Content == button1.Content)
{
button1.Visibility = Visibility.Collapsed;
selected_button.Visibility = Visibility.Collapsed;
points += 3;
}
else
{
points -= 1;
selected_button.Background = new SolidColorBrush(Colors.White);
}
selected_button = null;
//PageTitle.Text = "" + points;
}
else
{
selected_button = button1;
selected_button.Background = new SolidColorBrush(Colors.Green);
}
}
private void button2_Click(object sender, RoutedEventArgs e)
{
if (selected_button != null)
{
PageTitle.Text = "" + selected_button.Content + " " + button2.Content;
if (selected_button.Content == button2.Content)
{
button2.Visibility = Visibility.Collapsed;
selected_button.Visibility = Visibility.Collapsed;
points += 3;
}
else
{
points -= 1;
selected_button.Background = new SolidColorBrush(Colors.White);
}
selected_button = null;
//PageTitle.Text = "" + points;
}
else
{
selected_button = button2;
selected_button.Background = new SolidColorBrush(Colors.Green);
}
}
private void button11_Click(object sender, RoutedEventArgs e)
{
button11.Visibility = Visibility.Collapsed;
}
}
Please help :)

Drag and Drop Control in with RightToLeftLayout True

I used following code to drag and drop Button in C# and it works like charm when my Form.RightToLeftLayout=False,
but
when I set RightToLeftLayout=True
it doesnt work and move the control in wrong direction!!!
public partial class Form1 : Form
{
int xPosition;
int yPosition;
bool isDraged;
public Form1()
{
InitializeComponent();
}
private void btnMoveable_MouseDown(object sender, MouseEventArgs e)
{
this.Cursor = Cursors.SizeAll;
xPosition = e.X;
yPosition = e.Y;
isDraged = true;
}
private void btnMoveable_MouseUp(object sender, MouseEventArgs e)
{
isDraged = false;
this.Cursor = Cursors.Default;
}
private void btnMoveable_MouseMove(object sender, MouseEventArgs e)
{
if (isDraged)
{
btnMoveable.Left = btnMoveable.Left + e.X - xPosition;
btnMoveable.Top = btnMoveable.Top + e.Y - yPosition;
}
}
}
Well, you're discovering how RightToLeft is implemented. Everything is still in their normal logical position but the coordinate system is mirror-imaged along the Y-axis. So movement along the X-axis is inverted. You'll need to accommodate that. Fix:
int dx = e.X - xPosition;
if (this.RightToLeft == RightToLeft.Yes) dx = -dx;
btnMoveable.Left = btnMoveable.Left + dx;

canvas.DrawBitmap() executing at onPostExecute in AsyncTask but Bitmap not displaying

I am calling invalidate() which is calling onDraw(). The bitmap that I wish to show on the screen is not being displayed after running doInBackGround(). Can anyone help?
Here is what I have tested out so far.
When I place the same line of code
canvas.drawBitmap();
in onPreExecute() it works, but in onPostExecute() it does not display the expected results.
This is my code:
public class FloorAppActivity extends Activity {
private Context globalContext;
private Point displaySize;
private int displayWidth;
private int displayHeight;
private String floorID;
private String floorName;
private String floorGridNumStr;
private int floorGridNum;
private String floorNumStr;
private int positionX;
private int positionY;
private int XCoord;
private int YCoord;
private int ZCoord;
private float signalStr;
private Integer dBm;
private Bitmap floorPlan;
private Bitmap userMark;
private Bitmap redPin;
private FloorView floorView;
private Connection conn = null;
private Canvas canvas=null;
private int newScrollRectX=0;
private int newScrollRectY=0;
private Paint paint;
private boolean a = false;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
globalContext = this;
floorID = getIntent().getStringExtra("floorID");
floorName = getIntent().getStringExtra("floorName");
positionX = getIntent().getIntExtra("userPositionX",-1);
positionY = getIntent().getIntExtra("userPositionY",-1);
dBm = getIntent().getIntExtra("BestSignal", -1);
//Get the grid number
if(Integer.parseInt(floorName.substring(floorName.lastIndexOf("_")+1))<10)
floorGridNumStr = floorName.substring(8, 9);
else
floorGridNumStr = floorName.substring(8, 10);
floorGridNum = Integer.parseInt(floorGridNumStr);
floorNumStr = floorName.substring(5,7);
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
displaySize = new Point();
try {
// GetSize is not available in older models of Android
display.getSize(displaySize);
} catch (java.lang.NoSuchMethodError ignore) { // Older device
displaySize.x = display.getWidth();
displaySize.y = display.getHeight();
}
try {
InputStream source = getAssets().open(floorID);
floorPlan = BitmapFactory.decodeStream(source);
displayWidth = Math.min(displaySize.x, floorPlan.getWidth());
displayHeight = Math.min(displaySize.y, floorPlan.getHeight());
userMark = BitmapFactory.decodeResource(getResources(),R.drawable.star);
redPin = BitmapFactory.decodeResource(getResources(),R.drawable.redpin);
floorView = new FloorView(this);
setContentView(floorView);
}
catch (IOException e) {
MapServerAPI server = new MapServerAPI(globalContext,"Retrieving floor plan. Please wait...") {
#Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
if (bitmap == null)
Toast.makeText(globalContext, "Error in retrieving floor plan!", Toast.LENGTH_LONG).show();
else {
floorPlan = bitmap;
displayWidth = Math.min(displaySize.x, floorPlan.getWidth());
displayHeight = Math.min(displaySize.x, floorPlan.getHeight());
userMark = BitmapFactory.decodeResource(getResources(),R.drawable.star);
redPin = BitmapFactory.decodeResource(getResources(),R.drawable.redpin);
floorView = new FloorView(globalContext);
setContentView(floorView);
}
}
};
server.execute(floorID);
}
}
#Override
public void onResume() {
super.onResume();
registerReceiver(broadcastReceiver,new IntentFilter("FingerPrint_LOCATION_UPDATE"));
}
#Override
public void onPause() {
super.onPause();
unregisterReceiver(broadcastReceiver);
}
// listen for user location change
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
String result = intent.getStringExtra("location");
Toast.makeText(context,result,Toast.LENGTH_LONG).show();
String floorId = intent.getStringExtra("floorID");
floorName = intent.getStringExtra("name");
dBm = intent.getIntExtra("BestSignal", -1);
int userLocationX = intent.getIntExtra("userPositionX",-1);
int userLocationY = intent.getIntExtra("userPositionY",-1);
//Get the grid number
if(Integer.parseInt(floorName.substring(floorName.lastIndexOf("_")+1))<10)
floorGridNumStr = floorName.substring(8, 9);
else
floorGridNumStr = floorName.substring(8, 10);
floorGridNum = Integer.parseInt(floorGridNumStr);
floorNumStr = floorName.substring(5,7);
if(!floorId.equals(floorID)){
positionX = userLocationX;
positionY = userLocationY;
InputStream source=null;
try {
source = getAssets().open(floorID);
} catch (IOException e) {
}
floorPlan = BitmapFactory.decodeStream(source);
floorView.postInvalidate();
}
}
};
private class FloorView extends View {
private Rect displayRect; //rect we display to
private Rect scrollRect; //rect we scroll over our bitmap with
private int scrollRectX = 0; //current left location of scroll rect
private int scrollRectY = 0; //current top location of scroll rect
private float scrollByX = 0; //x amount to scroll by
private float scrollByY = 0; //y amount to scroll by
private float startX = 0; //track x from one ACTION_MOVE to the next
private float startY = 0; //track y from one ACTION_MOVE to the next
public FloorView(Context context) {
super(context);
// Destination rect for our main canvas draw. It never changes.
displayRect = new Rect(0, 0, displayWidth, displayHeight);
// Scroll rect: this will be used to 'scroll around' over the
// bitmap in memory.
if (positionX + displayWidth / 2 > floorPlan.getWidth())
scrollRectX = floorPlan.getWidth() - displayWidth;
else
scrollRectX = positionX - displayWidth / 2;
if (scrollRectX < 0)
scrollRectX = 0;
if (positionY + displayHeight / 2 > floorPlan.getHeight())
scrollRectY = floorPlan.getHeight() - displayHeight;
else
scrollRectY = positionY - displayHeight / 2;
if (scrollRectY < 0)
scrollRectY = 0;
scrollRect = new Rect(scrollRectX, scrollRectY, displayWidth, displayHeight);
}
#Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// Remember our initial down event location.
startX = event.getRawX();
startY = event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
float x = event.getRawX();
float y = event.getRawY();
// Calculate move update. This will happen many times
// during the course of a single movement gesture.
scrollByX = x - startX; //move update x increment
scrollByY = y - startY; //move update y increment
startX = x; //reset initial values to latest
startY = y;
invalidate(); //force a redraw
break;
}
return true; //done with this event so consume it
}
#Override
protected void onDraw(Canvas canvas1) {
canvas=canvas1;
// Our move updates are calculated in ACTION_MOVE in the opposite direction
// from how we want to move the scroll rect. Think of this as dragging to
// the left being the same as sliding the scroll rect to the right.
newScrollRectX = scrollRectX - (int)scrollByX;
newScrollRectY = scrollRectY - (int)scrollByY;
// Don't scroll off the left or right edges of the bitmap.
if (newScrollRectX < 0)
newScrollRectX = 0;
else if (newScrollRectX > (floorPlan.getWidth() - displayWidth))
newScrollRectX = (floorPlan.getWidth() - displayWidth);
// Don't scroll off the top or bottom edges of the bitmap.
if (newScrollRectY < 0)
newScrollRectY = 0;
else if (newScrollRectY > (floorPlan.getHeight() - displayHeight))
newScrollRectY = (floorPlan.getHeight() - displayHeight);
// We have our updated scroll rect coordinates, set them and draw.
scrollRect.set(newScrollRectX, newScrollRectY,
newScrollRectX + displayWidth, newScrollRectY + displayHeight);
paint = new Paint();
canvas.drawBitmap(floorPlan, scrollRect, displayRect, paint);
// Update user position
if (positionX >= newScrollRectX && positionX - newScrollRectX <= displayWidth
&& positionY >= newScrollRectY && positionY - newScrollRectY <= displayHeight)
canvas.drawBitmap(userMark,positionX-newScrollRectX-userMark.getWidth()/2,positionY-newScrollRectY-userMark.getHeight()/2,paint);
class AsyncTaskToConnect extends AsyncTask <Void, Void, Void>{
#Override
protected Void doInBackground(Void... cmd) {
// connect to database and retrieve values
return null;
}
#Override
protected void onPostExecute(Void v)
{//PE
if (positionX >= newScrollRectX && positionX - newScrollRectX <= displayWidth
&& positionY >= newScrollRectY && positionY - newScrollRectY <= displayHeight)
{
canvas.drawBitmap(redPin,480-newScrollRectX-userMark.getWidth()/2,90-newScrollRectY-userMark.getHeight()/2,paint);
}
//return null;
// Reset current scroll coordinates to reflect the latest updates,
// so we can repeat this update process.
scrollRectX = newScrollRectX;
scrollRectY = newScrollRectY;
}//PE
}
AsyncTaskToConnect[] asyncTaskC = null;
asyncTaskC = new AsyncTaskToConnect[1];
asyncTaskC[0] = new AsyncTaskToConnect();
asyncTaskC[0].executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
#Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
// Cache our new dimensions; we'll need them for drawing.
displayWidth = Math.min(w, floorPlan.getWidth());
displayHeight = Math.min(h, floorPlan.getHeight());
// Destination rect for our main canvas draw.
displayRect = new Rect(0, 0, displayWidth, displayHeight);
// Scroll rect: this will be used to 'scroll around' over the
// bitmap in memory.
if (positionX + displayWidth / 2 > floorPlan.getWidth())
scrollRectX = floorPlan.getWidth() - displayWidth;
else
scrollRectX = positionX - displayWidth / 2;
if (scrollRectX < 0)
scrollRectX = 0;
if (positionY + displayHeight / 2 > floorPlan.getHeight())
scrollRectY = floorPlan.getHeight() - displayHeight;
else
scrollRectY = positionY - displayHeight / 2;
if (scrollRectY < 0)
scrollRectY = 0;
scrollRect = new Rect(scrollRectX, scrollRectY, displayWidth, displayHeight);
super.onSizeChanged(w, h, oldw, oldh);
}
}
}
P.S. This is my first time posting. Please pardon me if i make mistakes in my post. Thanks.
I think the problem is that you are storing the Canvas object passed into the onDraw method. The object may not be valid after the onDraw method has returned.
It looks like you are trying to prepare a Bitmap on a background thread and then draw it on screen when it has been prepared. The way you do it is - prepare the Bitmap and just call invalidate on the View in onPostExecute method. Then in the onDraw method, you can take that Bitmap object and draw it using canvas.drawBitmap

Sorting ASP Datalist after BINDING

I am binding a DataList with dynamic values (ie distances from google api From a particular location.)
ie from x location :
10 km away
15 km away etc as follows
Using this code in ItemDataBound :
private void bindDataList(string location)
{
DataSet dstProperty = Tbl_PropertyMaster.getPropertiesByLocation(location);
dlstNearbyProperties.DataSource = dstProperty;
dlstNearbyProperties.DataBind();
}
.
protected void dlstNearbyProperties_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
Label lblPropId = (Label)e.Item.FindControl("lblPropId");
Label lblKmAway = (Label)e.Item.FindControl("lblKmAway");
Label lblPrice = (Label)e.Item.FindControl("lblPrice");
DataSet dstEnabledStat = Tbl_PropertyMaster.GetPropertyDetailsbyId(Convert.ToInt32(lblPropId.Text));
if (dstEnabledStat.Tables[0].Rows.Count > 0)
{
//string origin = "8.5572357 ,76.87649310000006";
string origin = InitialOrigin;
string destination = dstEnabledStat.Tables[0].Rows[0]["Latitude"].ToString() + "," + dstEnabledStat.Tables[0].Rows[0]["Longitude"].ToString();
lblKmAway.Text = devTools.getDistance(origin, destination) + " Away";
}
lblPrice.Text = getMinnimumOfRoomPrice(Convert.ToInt32(lblPropId.Text));
}
}
Is there a way to sort these value in ascendind or descening w.r.t distances .
NB: Distances are not DB values,they are dynamic.
Can this be sorted in a Button1_Click ?
Alrite after lot of hours of playing with codes I did it.
The following is for GRIDVIEW,Similar steps can be followed for DataList As well.
Page Load : I added an extra column 'Miles' to the already existing datatable
protected void Page_Load(object sender, EventArgs e)
{
dtbl = Tbl_PropertyMaster.SelectAllPropertyAndUserDetails().Tables[0];
dtbl.Columns.Add("Miles", typeof(int));
//userId = devTools.checkAdminLoginStatus();
if (!IsPostBack)
{
fillDlPhotoViewAll();
FillGrProperty();
}
}
Row Data Bound :
protected void grProperty_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataSet dstEnabledStat = Tbl_PropertyMaster.GetPropertyDetailsbyId(PropId);
if (dstEnabledStat.Tables[0].Rows.Count > 0)
{
string origin = InitialOrigin;
string destination = dstEnabledStat.Tables[0].Rows[0]["Latitude"].ToString() + "," + dstEnabledStat.Tables[0].Rows[0]["Longitude"].ToString();
decimal Kilometre=0.00M;
if(devTools.getDistance(origin, destination)!=0)
{
Kilometre=Convert.ToDecimal(devTools.getDistance(origin, destination))/1000;
}
lblmiles.Text = Kilometre.ToString() + "Kms";
dtbl.Rows[inn]["Miles"] = Convert.ToInt32(devTools.getDistance(origin, destination));
inn = inn + 1;
}
}
ViewState["dtbl"] = dtbl;
}
Sort by distance Button_Click:
protected void btnSort_Click(object sender, EventArgs e)
{
DataTable dataTable;
dataTable = (DataTable)ViewState["dtbl"];
if (dataTable.Rows.Count > 0)
{
dataTable.DefaultView.Sort = "Miles DESC";
dataTable.AcceptChanges();
grProperty.DataSource = dataTable;
grProperty.DataBind();
}
}

Resources