Hide/Change Sort expression link in gridview


Today I was reading http://www.asp.net forums for some Q/A  & I found one interesting Query regarding Gridview sorting. So I feel that let me share it with others also.

Query Posted by Kamran Shahid

I am using built in sorting in gridview. The links on the headers column shows like

javascript:__doPostBack(‘GridView1′,’Sort$au_fname’)

Is tehre any way I can change the display of that link like for example it may show # or au_fname only.

Solutions by Imran Baloch

With JQuery

<script language="javascript">  
$(function(){      
    $("a[href]").each(function(n){  
        if(this.href.indexOf("GridView1")>-1)  
        {  
            var a=this.href;  
            this.href="#";  
            $(this).click(function(event){  
                this.href=a;  
            });              
        }  
    });  
});  
</script>  

Without JQuery

<script language="javascript">  
 var tags = document.getElementsByTagName('a');  
 for (var i=0; i < tags.length; i++)  
 {  
      if(tags[i].href.indexOf("GridView1")>-1)   
      {  
            tags[i].custom1=tags[i].href;  
            tags[i].href="#";  
            tags[i].onclick=function(event){  
                alert(this.custom1);  
                thisthis.href=this.custom1;  
            }  
      }  
 }   
</script>  

Hope this will help !!!

Happy Programming

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s