Pages

Thursday, May 26, 2011

Clear All Controls In asp net by javascript


Add This in your server side event

string myScript = String.Format("ClearAllControls();");ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Blank", myScript, true);

Javascript Function
function ClearAllControls()
    {
        var pnlMain = document.getElementById("updPanelMain");
        var pnlMainControls = pnlMain.getElementsByTagName("input");
        var pnlMainddlControls = pnlMain.getElementsByTagName("select");
        var pnlMainControlstextarea = pnlMain.getElementsByTagName("textarea");
       
            for (i = 0; i <=pnlMainControlstextarea.length-1 ; i++)
            {       
             
                 pnlMainControlstextarea[i].disabled = false;
                    pnlMainControlstextarea[i].innerHTML ="";                   
               
            }
            for (i = 0; i <=pnlMainControls.length-1 ; i++)
            {       
                if (pnlMainControls[i].type == "text")
                {
                 pnlMainControls[i].disabled = false;
                    pnlMainControls[i].value ="";                   
                }
            }
            for (i = 0; i <=pnlMainddlControls.length-1 ; i++)
            {
                    if(pnlMainddlControls[i].options[0]!=null || pnlMainddlControls[i].options[0]!=undefined)
                    {
                        pnlMainddlControls[i].disabled = false;
                        pnlMainddlControls[i].options[0].selected = true;
                    }
            }
    }
Get Datetime field format in GridView

<% 
# DataBinder.Eval(Container.DataItem, "last_use_dt", "{0:dd/MM/yyyy}")%>

Auto SrNo in GridView
<%#Container.DataItemIndex+1 %>
-----------------------------------------------------------------------------------------------
Get Max From Data Table

decimal srno = 0;List<decimal> srnoList = DtlCollSecuOther.AsEnumerable().Select(t => t.Field<decimal>("srno")).Distinct().ToList();
srno = srnoList.Max();
 

Search This Blog