Tuesday, November 15, 2011

Position cursor after all contents in Asp.Net TextBox

<asp:TextBox ID="TextBox1" runat="server"
onfocus="FocusAtLast();"
 ></asp:TextBox>

    function FocusAtLast () {
       
    var inputField = document.getElementById('<%= TextBox1.ClientID %>');
    if (inputField != null && inputField.value.length> 0)
    {
    if (inputField.createTextRange)
    {
    var FieldRange = inputField.createTextRange();
    FieldRange.moveStart('character',inputField.value.length);
    FieldRange.collapse();
    FieldRange.select();
    }
    }
    }

Reference:

http://msdn.microsoft.com/en-us/library/ms535872%28v=VS.85%29.aspx

Wednesday, November 9, 2011

Sorting in Datatable using C#


DataTable dt = dt.Select("[anycondition]", "[column] desc", DataViewRowState.CurrentRows).CopyToDataTable();

Tuesday, November 8, 2011

Export Tree view into excel without using COM Objects


This code is used to export all tree nodes from telerik tree view. we can also implement to normal tree view.

Tuesday, November 1, 2011

DIV drag drop in JQuery

I come across one scenario that I need to create a pop up which should be draggable.
So I created one popup using JQuery.

Important thing is that i am using update panel in my page. i assigned one css class at design time.
my need is pop up should always open at top of page. if i drag and drop div at page bottom and close the div means , next it is opening only at bottom.

So in order to solve this problem i assign all css properties at run time in javascript on particular control on click event.

you can download jquery files from following links

http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js
http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js

Please add script references inside form tag.


Page Design:


function OpenPopup() {
var object = document.getElementById("makeMeDraggable");
object.style.display = "block";
object.style.borderWidth = "2px";
object.style.borderCollapse = "collapse";
object.style.borderStyle = "solid";
object.style.borderColor = "black";
object.style.zIndex = "71";
object.style.position = "fixed";
object.style.width = "75%";
object.style.top = "10px";
object.style.left = "10%";
object.style.cursor = "move";
object.style.backgroundColor = "Red";
}


<form id="form1" runat="server">
<script src="../Scripts/jquery.min.js" type="text/javascript"></script>
<script src="../Scripts/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(init); function init()
{ $('#makeMeDraggable').draggable(); }
</script>
<a onclick="OpenPopup();">Click here</a>
   
<div id="makeMeDraggable" style="display: none">
<div>
//Add your design here
// add any controls like grid to load dynamic data
</div>
</div>
</form>