Monday, October 18, 2010

Select Multiple Checkbox with Shift key in Gridview by javascript

Hello Friends,
Recently i was just looking at my Gridview where i have a checkbox in each row.. now i need to select all Check box.. for that lots of material is available on net..
and all are enough so i am not going to deep in it
check out this… http://www.codeproject.com/KB/grid/GridCheckBox.aspx

but now my problem was that i wanted to select few rows but not all
let’s say in my gridview the number of records are around 100.. and i want to check the checkbox of first 35 records
in that case i had to click on checkbox of all 35 rows.
i thought, like all mail accounts like gmail, yahoo, live and in may more…
i should be able to select multiple records by shift key.
means select the first record and pressing shift key select the 35st record so all the records in between will be selected..
and for that i found lots of jquery or any other javascripts.
but here i have tried to make something my own and i am happy to make it..
First With Shift Secod with Shift Selected with shift
here is code

on Page

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
        <Columns>
            <asp:BoundField DataField="ID" HeaderText="Id" />
            <asp:BoundField DataField="Name" HeaderText="Name" />
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox1" 

onclick="CheckAllCheckbox(document.getElementById('ctl00_ContentPlaceHolder1_GridView1'),this,event);"
                        runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>







on code Behind


protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           DataTable dt = new DataTable();
           dt.Columns.Add("ID");
           dt.Columns.Add("Name");
           DataRow dr;
           for (int i = 1; i < 130; i++)
           {
               dr = dt.NewRow();
               dr["ID"] = i;
               dr["Name"] = "Record No" + i.ToString();
               dt.Rows.Add(dr);
           }
           GridView1.DataSource = dt;
           GridView1.DataBind();
       }
   }
Javascript
var lst = null;
        function CheckAllCheckbox(ctrl, sValue, e) {
            var chkName = sValue.id;
            var arlstr = sValue.id.split(ctrl.id);
            var id = arlstr[1].split('_')[1].substring(3);

            var ee = (window.event) ? event : e;
            if (ee.shiftKey) {
                if (lst != null) {
                    var First = 0, last = 0;
                    if (parseInt(lst) > parseInt(id)) {
                        First = parseInt(id);
                        last = parseInt(lst);
                    }
                    else {
                        First = parseInt(lst);
                        last = parseInt(id);
                    }

                    for (i = First; i < last; i++) {                        
                        var p = (i <= 9 ? '0' + i : i);
                        var ctrlnew = chkName.replace('ctl' + id, 'ctl' + p);                        
                        document.getElementById(ctrlnew).checked = sValue.checked;
                    }                    
                }
            }
            lst = id;
        }
Here is the Source to Download http://cid-552998535cb9985d.office.live.com/self.aspx/.Public/SelectWithShift.rar Thanks

Saturday, September 4, 2010

Epic Browser

Background of Epic

The Epic Browser is the first-ever web browser for India and the first product from the software company Hidden Reflex.

Hidden Reflex is a software product startup founded by Alok Bhardwaj in 2007 and based in Bangalore. Alok, who was raised in the U.S., was inspired by the success of open source software and web 2.0 innovations. Hidden Reflex began as a team of three but soon progressed and now has dedicated teams working on two products simultaneously – the Epic Browser and NewsDrink. The company also has three patents pending related to its product innovations.

The company’s vision is to become the first globally recognized, consumer-oriented software product company in India. According to Alok Bhardwaj, CEO and Founder of Hidden Reflex, “We want to prove that India can be a hub for innovation in software and technology."

Our mission with the Epic browser is to create the most secure, most productive and most “Indian” browsing experience of any web browser!



What Someone might need in a browser..
  • help to blog
  • news search
  • store personal data
  • upload data directly from browser that of our Hard Drive
  • multiple language
  • attractive theaming/background
  • faster
  • Various Social Networking sites updates
  • Mails updates
  • Antivirus
  • Online News Channel
  • and lot more

all this available in a single 9MB application that is Epic Browser


 Interface

Please refer this page for mindblowing Interface http://www.epicbrowser.com/press.html


Every one must try Once...


 


Sunday, August 29, 2010

Access ViewState From ClassFile

teHello Friends

Manytime we need to use ViewState while working 3-tier Architecture but its difficult to use it.
here i have made a sample to use Viewstate from Classfile

ViewState:
Viewstate is an object of Class StateBag

 Here is sample of Viewstate in Class file
in this example we will add names from Textbox to gridview using Viewstate.
so
in code behind

<div>
                Name :
                <asp:TextBox ID="txtName" runat="server"></asp:TextBox><asp:Button ID="btnAdd" runat="server" Text="Add" />
            </div>
            <div>
                <asp:GridView ID="grvNames" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None">
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <Columns>
                        <asp:BoundField DataField="ID" HeaderText="No" />
                        <asp:BoundField DataField="SName" HeaderText="Name" />
                    </Columns>
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle BackColor="#999999" />
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                </asp:GridView>
            </div>


and in aspx.cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Controller_Default objController = new Controller_Default(this.ViewState);
        btnAdd.Click += new EventHandler(objController.btnAdd_Click);
    }
}


 Now Create a Controller file named Controller_Default.cs in a Folder named Controller
The Code in the Controller Class will go like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Data;
using System.Web.UI.WebControls;

public class Controller_Default
{
    #region Variables & contructors

    IDictionary _ViewState;
    public Controller_Default() { }

    public Controller_Default(IDictionary objStageBag)
    {
        _ViewState = objStageBag;
    }
    #endregion

    #region Events
    /// 
    /// Button Event to Add Name 
    /// 
    ///     ///     public void btnAdd_Click(object sender, EventArgs e)
    {
        Button btn = (Button)sender;
        try
        {
            DataTable dt = new DataTable();
            ViewStateClass objViewState = new ViewStateClass(_ViewState);
            if (objViewState.GetViewStateTable("TblNames") != null)
                dt = objViewState.GetViewStateTable("TblNames");
            else
                dt = CreateNewTable();

            DataRow dr = dt.NewRow();
            dr["ID"] = dt.Rows.Count + 1;
            dr["SName"] = ((TextBox)btn.Parent.FindControl("txtName")).Text.ToString();
            dt.Rows.Add(dr);

            objViewState.SetViewState("TblNames", dt);
            GridView grv = (GridView)btn.Parent.FindControl("grvNames");
            grv.DataSource = dt;
            grv.DataBind();

            ((TextBox)btn.Parent.FindControl("txtName")).Text = string.Empty;
            ((TextBox)btn.Parent.FindControl("txtName")).Focus();
        }
        catch (Exception Ex) { }
    }
    #endregion

    #region Methods
    /// 
    /// Method to Create New Table
    /// 
    /// 
    private DataTable CreateNewTable()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("ID");
        dt.Columns.Add("SName");
        return dt;
    }
    #endregion
}



in this code we have created and object Named objViewState of class ViewStateClass.

The Syntex objViewState.GetViewStateTable("TblNames") is used to get DataTable from ViewState
Same way  objViewState.SetViewState("TblNames", dt); Saves the DataTable in ViewState.
  
 Now here is the class ViewStateClass , you can download it from here
 in this class we have many methods to save different types like String,Int, Array and so on ... you can create same whichever you require.
you can download the source from Here

All The Best 

Thursday, August 26, 2010

Get Nth record from Table

Hello Friends Here is a simple query to get nth Record from Table
SELECT @NewPriority=Priority 
FROM (    SELECT 
                 Id
                , Priority
                , ROW_NUMBER() OVER (ORDER BY priority) as row 
         FROM Job 
         where IsDeleted=0     
               and Id not in ( select jobId from Job_Cylinder where IsDeleted=0)
       ) a
WHERE row=@cnt-(@NewPriority)+1
There are many ways to get this.. All the Best

Wednesday, April 14, 2010

Light-weight Popup using CSS and Javascript..

Hello Friends
Once Again with a Rocking point we have seen lots of Popup till now…..
all are good at their places just search on Google “Model Popup” and you will get a long list of examples and javascripts for popup…
Ajax Control toolkit Model Popup Extender http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/ModalPopup/ModalPopup.aspx
 then few more
 http://www.modalpopups.com/blog/
http://www.jquery-dev.com/2008/12/02/jqmodal-jquery-modal-popup-plugin
one more javascript framework is Dojo http://www.dojotoolkit.org/
here i am also one type of popup… but i am sure you will like it
because it don’t require any kind of configuration and dependencies…

    

it is combination of CSS and javascript… with 70:30 ratio….
means here CSS is used more and rest is javascript….
then also its more power full

so from first sight you can determine its light–weight compare to other model popups

here i have an example…
   1: <input id="Button1" type="button"

   2:      value="Dispay Message" onclick="ShowDiv('DivPopUp')" />





Drop the control on which you want to fire ModelPopup.. and assign javascript event to fire onclick="ShowDiv('DivPopUp')"




if you are using server control like


   1: <asp:Button ID="Button2" runat="server" Text="Dispay Message" />



then at Server Side code….


in Page_Load Event


   1: Button2.Attributes.Add("onclick", "ShowDiv('DivPopUp')");



now

Sunday, March 7, 2010

DataBase Specific Queries

Hello friends
Here are few Database Specific Queries
  • Select All Database list 
1: SELECT [name] FROM sys.databases
2: SELECT [name] FROM sys.sysdatabases
This will Result
Select All Database list


  • Select All Tables of particular Database. 
1: SELECT Name, type,type_desc FROM sys.objects 
2: where Type='u'
This will Result
Select All Tables of particular Database
  • Here Fields Type and Type_Desc are
Type Type_Desc
C CHECK_CONSTRAINT
D DEFAULT_CONSTRAINT
F FOREIGN_KEY_CONSTRAINT
FN SQL_SCALAR_FUNCTION
IF SQL_INLINE_TABLE_VALUED_FUNCTION
IT INTERNAL_TABLE
P SQL_STORED_PROCEDURE
PK PRIMARY_KEY_CONSTRAINT
S SYSTEM_TABLE
SQ SERVICE_QUEUE
TF SQL_TABLE_VALUED_FUNCTION
TR SQL_TRIGGER
U USER_TABLE
UQ UNIQUE_CONSTRAINT
V VIEW
can be more than this…
  • Select Columns from particular Table
1: SELECT column_name as [Column Name],data_type as [Data Type],Character_maximum_length as [Character Maximum Length]
2: FROM information_schema.columns
3: WHERE table_name = 'table_1'
This will Result

Select Columns from particular Table
 
All The Best

Friday, March 5, 2010

RemoteDataPass- pass data from one page to Remote Page

As i Committed in my previous post, that i will post code for ReportDataPass.

it is Quite difficult to pass Data from one Application to another application,
because here Cookie, Session variable will not help.
now a very simple way it Query string,  But as our previous condition, we don’t want to use Query string.
so the last way..
Post Method
as we know, in any server side scripting languages, like asp, jsp, PHP.. on submit button, the Data is posted to another page or to itself.
and using Request[“Filedname”]
we can have its Value. the same logic we are going to apply..
but as we are using VS, where we have facilities of Masterpages and Content page,so when we are using any ContentPage, in that case we can not have form and its Post method.

So we are going to make a dynamic Html Page, and  using dynamic Javascript we will post Data to another page.

So create a Class like this
   1: public class RemoteDataPass
   2: {
   3:     
   4:     private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection();
   5:     public string PostUrl = "";
   6:     public void Add(string FieldName, string Fieldvalue)
   7:     {
   8:         Inputs.Add(FieldName, Fieldvalue);
   9:     }
  10:  
  11:     public void Post()
  12:     {
  13:         System.Web.HttpContext.Current.Response.Clear();
  14:         System.Web.HttpContext.Current.Response.Write("<html><head></head><body onload=\"document.form1.submit()\">");
  15:         System.Web.HttpContext.Current.Response.Write(string.Format("<form name=\"form1\" method=\"post\" action=\"{0}\" >", PostUrl));
  16:         for (int i = 0; i < Inputs.Keys.Count; i++)
  17:         {
  18:             System.Web.HttpContext.Current.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", Inputs.Keys[i], Inputs[Inputs.Keys[i]]));
  19:         }
  20:         System.Web.HttpContext.Current.Response.Write("</form></body></html>");        
  21:         System.Web.HttpContext.Current.Response.End();
  22:     }
  23: }








now to post Data from our Source Page.



   1: RemoteDataPass RemotePost = new RemoteDataPass();
   2:         RemotePost.PostUrl = "http://ransandeep.blogspot.com/test.aspx";
   3:         RemotePost.Add("FirstField", "Sandeep");        
   4:         RemotePost.Post(); 










now at Receiving page



   1: protected void Page_Load(object sender, EventArgs e)
   2:    {
   3:         if (Request.Form[ "FirstField" ] != null  )
   4:         {
   5:            Response.Write( "FirstField : "  + Request.Form[ "FirstField" ] +  "</br>" ) ;
   6:         }         
   7:    }







So this is Simple after getting know….





All the best..

Popup new Window by Javascript

A very Common trick
Open a new window as Popup by javascript…
Clicking on any Server Button

   1: <asp:Button ID="Button1" 
   2:                 runat="server" 
   3:                 OnClientClick="window.open('Page2.aspx',null,'height=200,width=400
   4:                         ,status=yes,toolbar=no,menubar=no,location=no,scroll=no');
   5:                         return false;"
   6:                 Text="Button" />







All The Best..

Saturday, February 27, 2010

IsCrossPagePostback–pass data from one page to another

Hello friends
again with new concept..

Page.IsCrossPagePostBack
in many case we are supposed to pass data from one page to another page.

So we can pass data through Querystring, ,
this options are quiet helpful when Data is less in quantity.. but now what if we want whole page to another page… ?

and in previous page Data is in very big amount around 20 – 40 fields…
so it is not feasible to pass that data in querystring or storing all data in session.

there also another ways, like Cookie or hiddenfields using Post method.. but
all this require more trouble..

but what if we get previous page controls like it is “on same page”

for that we have a good option called IsCrossPagePostback 

it is same like our Page.IsPostBack.
Page.IsPostBack treats only for current page’s postback
but to track weather postback is from Current page or previous page we can use IsCrossPagePostBack.

One Important Note : Respose. Redirect will not help us to track IsCrossPagePostBack
for that we must have Server.Transfer or PostbackURL of Button control


So here we have a sample of IsCrossPagePostBack

in First.aspx
   1: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="First.aspx.cs" Inherits="First" %>
   2:  
   3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   4: <html xmlns="http://www.w3.org/1999/xhtml">
   5: <head runat="server">
   6:     <title>First Page</title>
   7: </head>
   8: <body>
   9:     <form id="form1" runat="server">
  10:     <div>
  11:         <asp:Label ID="label1" runat="server" Text="This is First Page"></asp:Label>
  12:         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  13:         <asp:Button ID="Button1" runat="server" Text="Pass To Second Page" PostBackUrl="~/Second.aspx" />
  14:     </div>
  15:     </form>
  16: </body>
  17: </html>










Now in Second.aspx




   1: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Second.aspx.cs" Inherits="Second" %>
   2:  
   3: <%@ PreviousPageType VirtualPath="~/First.aspx" %>
   4: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   5: <html xmlns="http://www.w3.org/1999/xhtml">
   6: <head runat="server">
   7:     <title>Second Page</title>
   8: </head>
   9: <body>
  10:     <form id="form1" runat="server">
  11:     <div>
  12:         <asp:Label ID="Label1" runat="server"></asp:Label>
  13:     </div>
  14:     </form>
  15: </body>
  16: </html>









in this page very important line is  line no 3


here the Reference is set to inherit controls of Previous page



   1: public partial class Second : System.Web.UI.Page
   2: {
   3:     protected void Page_Load(object sender, EventArgs e)
   4:     {
   5:         if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
   6:         {
   7:             TextBox text = PreviousPage.FindControl("TextBox1") as TextBox;
   8:  
   9:             if (text != null)
  10:             {
  11:                 Label1.Text = " This is from From First Page : " + text.Text;
  12:             }
  13:             else
  14:             {
  15:                 Label1.Text = "Empty !!!!";
  16:             }
  17:         }
  18:     }
  19: }









in page load it is very easy to fetch data of previous page..





so this is very simple if the pages are within same project..





we will see very soon when page is in another project means RemotecrossPage





All The Best

Thursday, February 25, 2010

Query for Recursive Data

Hi friends..

here is the query for Data kind of Recursive.
For Example….
for a particular thread in forum, its Comments
so in this case…
The Data structure will be like this
Table_3
Id int
ThreadText nvarchar(MAX)
PostedBy int
PostedOn DateTime
ParentId int

Now if we want to have the hierarchical View of Data.
We can have query like this
   1: SELECT     T2.id , T2.name ,T1.id as ParentId, T1.name as ParentName
   2: FROM         Table_3 AS T1 INNER JOIN
   3:                       Table_3 AS T2 ON T1.id = T2.parentid




now the Task is to Arrange the Data how you want to Display..





All the best