<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-777933054050893742</id><updated>2012-01-19T00:13:41.705+05:30</updated><category term='subtotal gridview'/><category term='Click Grid'/><category term='DateTime Format Strings'/><category term='gridview nesting'/><category term='javascript'/><category term='Click GridView'/><category term='rowclick'/><category term='remove div input node javascript jquery'/><category term='validations'/><category term='repeater paging pageddatasource'/><category term='gridview'/><category term='Strip Space'/><category term='zindex div'/><category term='URL Check'/><category term='?? Operator'/><category term='JavaScript Trim'/><category term='ASPX'/><category term='ASP.NET'/><category term='Coalesce Operator'/><category term='Check for 404'/><category term='Click Row'/><category term='row selection'/><category term='Remove Spaces'/><category term='div over div'/><category term='selectable row'/><category term='Ternary Operator'/><category term='gridview sorting paging'/><category term='Invalid postback or callback argument'/><category term='App_Browsers'/><category term='gridview with javascript'/><category term='maintain checkbox state multiple gridviews'/><category term='jquery visual studio'/><category term='URL Checker'/><category term='URL Exist'/><category term='javascript nesting gridview'/><category term='GridViewRow HyperLink'/><category term='nested gridview'/><category term='jquery microsoft'/><category term='JavaScript Strip Spaces'/><category term='javascript gridview'/><category term='W3c Validation'/><category term='inser custom row gridview'/><category term='paging and filtering gridview'/><category term='JavaScript Space Trim'/><category term='listview paging'/><category term='DateTime Formats'/><category term='javascript div'/><category term='C#'/><category term='jquery'/><category term='select button'/><category term='copy datatable row'/><category term='gridviewrow'/><category term='image data type gridview'/><category term='child parent gridivew'/><category term='JavaScript Trim Space'/><category term='Grid Row HyperLink'/><category term='eventvalidation false'/><category term='__doPostBack object expected'/><category term='modal div'/><category term='Custom DateTime Formats'/><category term='there is no attribute &quot;border&quot;'/><category term='popup div'/><category term='gridview checkbox paging maintaining persisting state'/><category term='gridview filtering datalist filter alphabet'/><category term='Clickable GridViewRow'/><title type='text'>Coding Nuances</title><subtitle type='html'>A tech blog to core.
Concentrating mainly on ASP.NET and Javascript</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://blog.codovations.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>33</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-5555235988479552191</id><published>2011-04-15T19:15:00.010+05:30</published><updated>2011-04-16T13:32:27.484+05:30</updated><title type='text'>Tutorial - Post data on a Facebook Company Page as Admin</title><content type='html'>Its been a while I have blogged about something.&lt;br /&gt;Have been working on the Facebook API and one of the requirement is to post data into a Facebook company page from one's website.&lt;br /&gt;&lt;br /&gt;Here is a step by step procedure on posting data to a company page(on which you have admin rights) using the Facebook API.&lt;br /&gt;Feel free to skip the first two steps if you know how to set up a Facebook Application and to create pages in Facebook.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 1 - Creating a Facebook Application&lt;/b&gt; &lt;br /&gt;&lt;br /&gt;Sign in to your Facebook Account and key in the following URL to your address bar&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.facebook.com/developers/createapp.php"&gt;http://www.facebook.com/developers/createapp.php&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Set Application Name as "My Demo Application"&lt;/blockquote&gt;&lt;br /&gt;Now I am adding the following data also to the Website tab of the core settings&lt;br /&gt;(Lets come to that later)&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Set Site URL as http://localhost/FacebookPost/&lt;/blockquote&gt;&lt;br /&gt;After entering, click on the Save Changes Button.&lt;br /&gt;Now you will be re directed to a page where your App Settings are displayed.&lt;br /&gt;Copy the values App ID, App Key and App Secret and store them securely.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 2 - Creating a Facebook Page&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Now, key in the following URL to your address bar&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.facebook.com/pages/create.php"&gt;http://www.facebook.com/pages/create.php&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Now select the Page Type. Here is what I selected.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Type         : Company, Organisation (Click on the type you want to create.&lt;br /&gt;Category     : Computers/Technology&lt;br /&gt;Comapany Name: MyCompany&lt;/blockquote&gt;&lt;br /&gt;Now agree to the Facebook Pages Terms and click Get Started.&lt;br /&gt;Your page is created by Facebook and you will be landed on a URL like that&lt;br /&gt;http://www.facebook.com/pages/&lt;page_name&gt;/&lt;page_id&gt;?created&lt;br /&gt;Please copy the PageID and store it securely.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 3 - Create a website locally in your system&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Open up your Visual Studio and Create an empty website. &lt;br /&gt;Create a page "Default.aspx" and run the website and allow the web.config to be created.&lt;br /&gt;&lt;br /&gt;(I have mapped my site to my IIS with the application name FacebookPost.&lt;br /&gt;Please note that it is being done to match the Site URL I have set at the Facebook Application Page)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 4 - Pick a Facebook C# SDK to communicate with the Facebook Graph API.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;My research came up with two options&lt;br /&gt;1. Use the &lt;a href="http://developers.facebook.com/blog/post/395/"&gt;Facebook's own lesser used SDK&lt;/a&gt; found at GitHub ( &lt;a href="https://github.com/facebook/csharp-sdk"&gt;link here&lt;/a&gt; )&lt;br /&gt;&lt;br /&gt;2. Use the more widely used third party C# SDK hosted at Codeplex ( &lt;a href="http://facebooksdk.codeplex.com/"&gt;link here&lt;/a&gt; )&lt;br /&gt;&lt;br /&gt;I preferred Facebook's own SDK. Actually, you can also write your own API if you want. Its set of simple WebRequest/WebResponse. So I went to GitHub where the SDK was hosted and downloaded the folder named facebook and changed it to Facebook ( :) Pascal Casing) and pasted it inside my App_Code&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 5 - Modify your AppSettings at web.config&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Remember those AppID, AppKey, AppSecret, PageID I asked you to keep securely?&lt;br /&gt;Lets now store them at AppSettings of web.config.&lt;br /&gt;(Ideally you would be much better of encrypting them, but details on encrypting is beyond the scope of this tutorial.)&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:xml"&gt;&amp;lt;appSettings&amp;gt;&lt;br /&gt;    &amp;lt;add key=&amp;quot;AppID&amp;quot; value=&amp;quot;Your App ID&amp;quot;/&amp;gt;&lt;br /&gt;    &amp;lt;add key=&amp;quot;AppKey&amp;quot; value=&amp;quot;Your App Key&amp;quot;/&amp;gt;&lt;br /&gt;    &amp;lt;add key=&amp;quot;AppSecret&amp;quot; value=&amp;quot;Your App Secret&amp;quot;/&amp;gt;&lt;br /&gt;    &amp;lt;add key=&amp;quot;PageID&amp;quot; value=&amp;quot;Your Page ID&amp;quot;/&amp;gt;&lt;br /&gt;  &amp;lt;/appSettings&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;b&gt;Step 6 - Create a form for entering the data&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Open up Default.aspx in Visual Studio and change Source like this.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:xhtml"&gt;&amp;lt;html xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;head runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;title&amp;gt;Codovations Demo - Posting to Facebook Company Page&amp;lt;/title&amp;gt;&lt;br /&gt;    &amp;lt;style type=&amp;quot;text/css&amp;quot;&amp;gt;&lt;br /&gt;        .title {&lt;br /&gt;            display:inline-block;&lt;br /&gt;            vertical-align:top;&lt;br /&gt;            width:100px;   &lt;br /&gt;        }&lt;br /&gt;    &amp;lt;/style&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;    &amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;div&amp;gt;&lt;br /&gt;    &amp;lt;label class=&amp;quot;title&amp;quot;&amp;gt;Message&amp;lt;/label&amp;gt;&amp;lt;asp:TextBox ID=&amp;quot;MessageText&amp;quot; runat=&amp;quot;server&amp;quot; TextMode=&amp;quot;MultiLine&amp;quot; Width=&amp;quot;200px&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;    &amp;lt;label class=&amp;quot;title&amp;quot;&amp;gt;Name&amp;lt;/label&amp;gt;&amp;lt;asp:TextBox ID=&amp;quot;NameText&amp;quot; runat=&amp;quot;server&amp;quot; Width=&amp;quot;200px&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;    &amp;lt;label class=&amp;quot;title&amp;quot;&amp;gt;Description&amp;lt;/label&amp;gt;&amp;lt;asp:TextBox ID=&amp;quot;DescriptionText&amp;quot; runat=&amp;quot;server&amp;quot; TextMode=&amp;quot;MultiLine&amp;quot; Width=&amp;quot;200px&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;    &amp;lt;label class=&amp;quot;title&amp;quot;&amp;gt;Picture(URL)&amp;lt;/label&amp;gt;&amp;lt;asp:TextBox ID=&amp;quot;PictureText&amp;quot; runat=&amp;quot;server&amp;quot; Width=&amp;quot;200px&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;    &amp;lt;label class=&amp;quot;title&amp;quot;&amp;gt;Caption&amp;lt;/label&amp;gt;&amp;lt;asp:TextBox ID=&amp;quot;CaptionText&amp;quot; runat=&amp;quot;server&amp;quot; Width=&amp;quot;200px&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;    &amp;lt;label class=&amp;quot;title&amp;quot;&amp;gt;Link&amp;lt;/label&amp;gt;&amp;lt;asp:TextBox ID=&amp;quot;LinkText&amp;quot; runat=&amp;quot;server&amp;quot; Width=&amp;quot;200px&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;    &amp;lt;label class=&amp;quot;title&amp;quot;&amp;gt;&amp;lt;/label&amp;gt;&lt;br /&gt;        &amp;lt;asp:Button ID=&amp;quot;PostToCompanyButton&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;                Text=&amp;quot;Post to Company Page&amp;quot; onclick=&amp;quot;PostToCompanyButton_Click&amp;quot;/&amp;gt;&lt;br /&gt;    &amp;lt;/div&amp;gt;&lt;br /&gt;    &amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;b&gt;Step 7 - Posting data on the Company Page.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;This is the trickiest part in this project. Facebook provides no straight forward way to post data to a company page. Here is how we achieve that.&lt;br /&gt;&lt;br /&gt;First we will request oAuth from Facebook and on successful authorisation we get an access token.&lt;br /&gt;Using the token we fetch "me/accounts" and will check in that account array, an account that matches the stored PageID. If found, we fetch the associated accesstoken for that page. When we get that we post the content to "me/feeds" using that accesstoken like this.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:csharp"&gt;if (Request.Params["code"] != null)&lt;br /&gt;{&lt;br /&gt;    Status.Text = "";&lt;br /&gt;    string accessToken = GetAccessToken(Request.Params["code"]);&lt;br /&gt;    FacebookAPI api = new FacebookAPI(accessToken);&lt;br /&gt;&lt;br /&gt;    JSONObject me = api.Get("me/accounts");&lt;br /&gt;    Dictionary&lt;string, JSONObject&gt; dictionary = me.Dictionary;&lt;br /&gt;    JSONObject myPage = me.Dictionary["data"].Array&lt;br /&gt;        .SingleOrDefault(d =&gt; d.Dictionary["id"].String.Equals(ConfigurationManager.AppSettings["PageID"].ToString()));&lt;br /&gt;    if (myPage != null)&lt;br /&gt;    {&lt;br /&gt;        Dictionary&lt;string, string&gt; parameters = Session["DataForFacebook"] as Dictionary&lt;string, string&gt;;&lt;br /&gt;        Session.Remove("DataForFacebook");&lt;br /&gt;        string newToken = myPage.Dictionary["access_token"].String;&lt;br /&gt;        var app = new FacebookAPI(newToken);&lt;br /&gt;        var response = app.Post("me/feed", parameters);&lt;br /&gt;        if (response != null &amp;&amp; response.Dictionary[""] != null)&lt;br /&gt;        {&lt;br /&gt;            Status.Text = "Data posted successfully to company page.";&lt;br /&gt;            ClearData();&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            Status.Text = "An error occured while posting.";&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;Two helper methods used are &lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:csharp"&gt;private string GetAccessToken(string accessToken)&lt;br /&gt;    {       &lt;br /&gt;        Dictionary&lt;string, string&gt; args = GetOauthTokens(accessToken);&lt;br /&gt;        return args["access_token"];&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private Dictionary&lt;string, string&gt; GetOauthTokens(string accessToken)&lt;br /&gt;    {&lt;br /&gt;        Dictionary&lt;string, string&gt; tokens = new Dictionary&lt;string, string&gt;();&lt;br /&gt;        try&lt;br /&gt;        {&lt;br /&gt;            string url = String.Format("{0}client_id={1}&amp;redirect_uri={2}&amp;client_secret={3}&amp;code={4}&amp;scope={5}",&lt;br /&gt;                            "https://graph.facebook.com/oauth/access_token?",&lt;br /&gt;                            ConfigurationManager.AppSettings["AppID"].ToString(),&lt;br /&gt;                            "http://localhost/FacebookPost/Default.aspx",&lt;br /&gt;                            ConfigurationManager.AppSettings["AppSecret"].ToString(),&lt;br /&gt;                            accessToken,&lt;br /&gt;                            "publish_stream,offline_access,manage_pages");&lt;br /&gt;&lt;br /&gt;            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;&lt;br /&gt;            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)&lt;br /&gt;            {&lt;br /&gt;                StreamReader reader = new StreamReader(response.GetResponseStream());&lt;br /&gt;                string retVal = reader.ReadToEnd();&lt;br /&gt;&lt;br /&gt;                foreach (string token in retVal.Split('&amp;'))&lt;br /&gt;                {&lt;br /&gt;                    tokens.Add(token.Substring(0, token.IndexOf("=")),&lt;br /&gt;                        token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        catch (Exception err)&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;        return tokens;&lt;br /&gt;    }&lt;/pre&gt;&lt;br /&gt;Thats all to it. Happy coding.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-5555235988479552191?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/5555235988479552191/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2011/04/tutorial-post-data-on-facebook-company.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/5555235988479552191'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/5555235988479552191'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2011/04/tutorial-post-data-on-facebook-company.html' title='Tutorial - Post data on a Facebook Company Page as Admin'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-5527242092047727167</id><published>2011-01-18T16:55:00.000+05:30</published><updated>2011-01-18T16:55:43.057+05:30</updated><title type='text'>Generating PDF from DataTable using iTextSharp</title><content type='html'>iTextSharp is a wonderful open-source tool for generating PDF in C#.&lt;br /&gt;&lt;br /&gt;Here is a simple generic helper class for Exporting data from a DataTable to a PDF file.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:csharp"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Data;&lt;br /&gt;&lt;br /&gt;using iTextSharp.text;&lt;br /&gt;using iTextSharp.text.pdf;&lt;br /&gt;&lt;br /&gt;namespace yetanothercoder&lt;br /&gt;{&lt;br /&gt;    /// &lt;summary&gt;&lt;br /&gt;    /// Summary description for CreatePdf&lt;br /&gt;    /// &lt;/summary&gt;&lt;br /&gt;    public class PDFExporter&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;        private readonly DataTable dataTable;&lt;br /&gt;        private readonly string fileName;&lt;br /&gt;        private readonly bool timeStamp;&lt;br /&gt;&lt;br /&gt;        public PDFExporter(DataTable dataTable, string fileName, bool timeStamp)&lt;br /&gt;        {&lt;br /&gt;            this.dataTable = dataTable;&lt;br /&gt;            this.fileName = timeStamp ? String.Format("{0}-{1}", fileName, GetTimeStamp(DateTime.Now)) : fileName;&lt;br /&gt;            this.timeStamp = timeStamp;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public void ExportPDF()&lt;br /&gt;        {&lt;br /&gt;            HttpResponse Response = HttpContext.Current.Response;&lt;br /&gt;            Response.Clear();&lt;br /&gt;            Response.ContentType = "application/octet-stream";&lt;br /&gt;            Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".pdf");&lt;br /&gt;&lt;br /&gt;            // step 1: creation of a document-object&lt;br /&gt;            Document document = new Document(PageSize.A4, 10, 10, 90, 10);&lt;br /&gt;&lt;br /&gt;            // step 2: we create a writer that listens to the document&lt;br /&gt;            PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream);&lt;br /&gt;&lt;br /&gt;            //set some header stuff&lt;br /&gt;            document.AddTitle(fileName);&lt;br /&gt;            document.AddSubject(String.Format("Table of {0}", fileName));&lt;br /&gt;            document.AddCreator("www.yetanothercoder.com");&lt;br /&gt;            document.AddAuthor("naveenj");&lt;br /&gt;&lt;br /&gt;            // step 3: we open the document&lt;br /&gt;            document.Open();&lt;br /&gt;&lt;br /&gt;            // step 4: we add content to the document&lt;br /&gt;            CreatePages(document);&lt;br /&gt;&lt;br /&gt;            // step 5: we close the document&lt;br /&gt;            document.Close();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private void CreatePages(Document document)&lt;br /&gt;        {&lt;br /&gt;            document.NewPage();&lt;br /&gt;            document.Add(FormatPageHeaderPhrase(dataTable.TableName));&lt;br /&gt;            PdfPTable pdfTable = new PdfPTable(dataTable.Columns.Count);&lt;br /&gt;            pdfTable.DefaultCell.Padding = 3;&lt;br /&gt;            pdfTable.WidthPercentage = 100; // percentage&lt;br /&gt;            pdfTable.DefaultCell.BorderWidth = 2;&lt;br /&gt;            pdfTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;&lt;br /&gt;&lt;br /&gt;            foreach (DataColumn column in dataTable.Columns)&lt;br /&gt;            {&lt;br /&gt;                pdfTable.AddCell(FormatHeaderPhrase(column.ColumnName));&lt;br /&gt;            }&lt;br /&gt;            pdfTable.HeaderRows = 1;  // this is the end of the table header&lt;br /&gt;            pdfTable.DefaultCell.BorderWidth = 1;&lt;br /&gt;&lt;br /&gt;            foreach (DataRow row in dataTable.Rows)&lt;br /&gt;            {&lt;br /&gt;                foreach (object cell in row.ItemArray)&lt;br /&gt;                {&lt;br /&gt;                    //assume toString produces valid output&lt;br /&gt;                    pdfTable.AddCell(FormatPhrase(cell.ToString()));&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            document.Add(pdfTable);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private static Phrase FormatPageHeaderPhrase(string value)&lt;br /&gt;        {&lt;br /&gt;            return new Phrase(value, FontFactory.GetFont(FontFactory.TIMES, 10, Font.BOLD, new BaseColor(255, 0, 0)));&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private static Phrase FormatHeaderPhrase(string value)&lt;br /&gt;        {&lt;br /&gt;            return new Phrase(value, FontFactory.GetFont(FontFactory.TIMES, 8, Font.UNDERLINE, new BaseColor(0, 0, 255)));&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private Phrase FormatPhrase(string value)&lt;br /&gt;        {&lt;br /&gt;            return new Phrase(value, FontFactory.GetFont(FontFactory.TIMES, 8));&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private string GetTimeStamp(DateTime value)&lt;br /&gt;        {&lt;br /&gt;            return value.ToString("yyyyMMddHHmmssffff");&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now if you have an Export to Excel Button, you can generate pdf easily like this&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:csharp"&gt;&lt;br /&gt;protected void ExportToPDFLink_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    PDFExporter pdf = new PDFExporter(GetCostumers(), "customer", true);&lt;br /&gt;    pdf.ExportPDF();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-5527242092047727167?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/5527242092047727167/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2011/01/generating-pdf-from-datatable-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/5527242092047727167'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/5527242092047727167'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2011/01/generating-pdf-from-datatable-using.html' title='Generating PDF from DataTable using iTextSharp'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-2652204024412377972</id><published>2011-01-18T14:56:00.003+05:30</published><updated>2011-01-18T15:01:00.302+05:30</updated><title type='text'>SQLite in ASP.NET Web Forms</title><content type='html'>What is SQLite?&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;SQLite is a in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. &lt;/blockquote&gt;&lt;br /&gt;SQLite is a must have tool for manipulating database for small to mid size projects, there by cutting the cost of maintaining an extra database server. Its very fast and has less percentage of crashing also.&lt;br /&gt;Next, download an SQLite Manager from which we can create and manipulate a sample database and its objects. For that I used the &lt;a href="https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/"&gt;SQLite Manager add on for Firefox&lt;/a&gt;. Feel free to use any other tools. &lt;br /&gt;Now we are all set to use the SQLite database in our ASP.NET application. &lt;br /&gt;&lt;br /&gt;Steps to follow&lt;br /&gt;&lt;br /&gt;1. Create a Sample Database called Northwind.sqlite using the firefix addon.&lt;br /&gt;2. Add a table named Customers to it with some fields and some dummy data to it.&lt;br /&gt;3. Create an empty website in .NET 3.5 using Visual Studio&lt;br /&gt;4. Create an App_Data folder in it and place the Northwind.sqlite to it&lt;br /&gt;5. Add to the empty website as reference, the dll&lt;br /&gt;&lt;pre class="brush:csharp"&gt;using System.Data.SQLite&lt;/pre&gt;6. Create a default page in your application and place a gridview in that&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:xml"&gt;&amp;lt;asp:GridView ID=&amp;quot;CustomersGrid&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;7. At code behind, add reference to System.Data.SQLite;&lt;br /&gt;8. Write the code to get data from Customers Table here.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:csharp"&gt;private void BindCustomerGrid()&lt;br /&gt;{&lt;br /&gt;    string commandText = "SELECT * FROM Customers";&lt;br /&gt;    string path_to_db = System.IO.Path.Combine(Server.MapPath("."), "App_Data", "Northwind.sqlite3");&lt;br /&gt;    string connectionString = String.Format("Data Source={0};Version=3;", path_to_db);&lt;br /&gt;    DataTable dataTable = new DataTable();&lt;br /&gt;    using (SQLiteConnection connection = new SQLiteConnection(connectionString))&lt;br /&gt;    {&lt;br /&gt;        using (SQLiteCommand cmd = new SQLiteCommand(commandText, connection))&lt;br /&gt;        {&lt;br /&gt;            cmd.CommandType = CommandType.Text;&lt;br /&gt;            using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd))&lt;br /&gt;            {&lt;br /&gt;                adapter.Fill(dataTable);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    CustomersGrid.DataSource = dataTable;&lt;br /&gt;    CustomersGrid.DataBind();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Thats all to it. Happy Coding!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-2652204024412377972?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/2652204024412377972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2011/01/sqlite-in-aspnet-web-forms.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/2652204024412377972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/2652204024412377972'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2011/01/sqlite-in-aspnet-web-forms.html' title='SQLite in ASP.NET Web Forms'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-7454006716829230492</id><published>2010-12-07T18:55:00.004+05:30</published><updated>2010-12-07T18:59:40.749+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='maintain checkbox state multiple gridviews'/><title type='text'>Maintaining CheckBox State of multiple GridViews</title><content type='html'>Almost two years back, I did a post on &lt;a target="_blank" href="http://fun2code.blogspot.com/2009/02/maintaining-state-of-checkbox-in.html"&gt;Maintaining State of Checkbox while Paging in Gridview&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This post is an extension to it. this is the code to maintain CheckBox states of multiple gridviews in a page.&lt;br /&gt;&lt;br /&gt;The logic is simple. We are storing the primary keys of the checkboxes that are checked into a List&amp;lt;T&amp;gt; where T = data type of the primary key. This is done at PageIndexChanging before we change the page index and re-bind the GridView. And at RowDataBound we are checking whether the DataKeyName(primary key) of each row is in the List&lt;t&gt;. If present , we mark the CheckBox as checked.&lt;br /&gt;&lt;br /&gt;At ASPX&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:xhtml"&gt;&amp;lt;asp:GridView ID=&amp;quot;gvProducts&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;            AllowPaging=&amp;quot;True&amp;quot; &lt;br /&gt;            AutoGenerateColumns=&amp;quot;False&amp;quot;&lt;br /&gt;            DataKeyNames=&amp;quot;ProductID&amp;quot;&lt;br /&gt;            OnPageIndexChanging=&amp;quot;gvProducts_PageIndexChanging&amp;quot; &lt;br /&gt;            OnRowDataBound=&amp;quot;gvProducts_RowDataBound&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;Columns&amp;gt;&lt;br /&gt;        &amp;lt;asp:TemplateField HeaderText=&amp;quot;Select&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;                &amp;lt;asp:CheckBox ID=&amp;quot;chkSelect&amp;quot; runat=&amp;quot;server&amp;quot; /&amp;gt;&lt;br /&gt;            &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;        &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;        &amp;lt;asp:BoundField DataField=&amp;quot;ProductID&amp;quot; HeaderText=&amp;quot;ProductID&amp;quot; InsertVisible=&amp;quot;False&amp;quot;&lt;br /&gt;        ReadOnly=&amp;quot;True&amp;quot; SortExpression=&amp;quot;ProductID&amp;quot; /&amp;gt;&lt;br /&gt;        &amp;lt;asp:BoundField DataField=&amp;quot;ProductName&amp;quot; HeaderText=&amp;quot;ProductName&amp;quot; SortExpression=&amp;quot;ProductName&amp;quot; /&amp;gt;&lt;br /&gt;    &amp;lt;/Columns&amp;gt;&lt;br /&gt;&amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;&amp;lt;asp:GridView ID=&amp;quot;gvCustomers&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;            AllowPaging=&amp;quot;True&amp;quot; &lt;br /&gt;            AutoGenerateColumns=&amp;quot;False&amp;quot;&lt;br /&gt;            DataKeyNames=&amp;quot;CustomerID&amp;quot;&lt;br /&gt;            OnPageIndexChanging=&amp;quot;gvCustomers_PageIndexChanging&amp;quot; &lt;br /&gt;            OnRowDataBound=&amp;quot;gvCustomers_RowDataBound&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;Columns&amp;gt;&lt;br /&gt;        &amp;lt;asp:TemplateField HeaderText=&amp;quot;Select&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;                &amp;lt;asp:CheckBox ID=&amp;quot;chkSelect&amp;quot; runat=&amp;quot;server&amp;quot; /&amp;gt;&lt;br /&gt;            &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;        &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;        &amp;lt;asp:BoundField DataField=&amp;quot;CustomerID&amp;quot; HeaderText=&amp;quot;ID&amp;quot; InsertVisible=&amp;quot;False&amp;quot; /&amp;gt;&lt;br /&gt;        &amp;lt;asp:BoundField DataField=&amp;quot;CompanyName&amp;quot; HeaderText=&amp;quot;CompanyName&amp;quot;  /&amp;gt;&lt;br /&gt;    &amp;lt;/Columns&amp;gt;&lt;br /&gt;&amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;At ASPX.CS&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:csharp"&gt;private List&amp;lt;int&amp;gt; ProductIDs&lt;br /&gt;{&lt;br /&gt;    get&lt;br /&gt;    {&lt;br /&gt;        if (this.ViewState[&amp;quot;ProductIDs&amp;quot;] == null)&lt;br /&gt;        {&lt;br /&gt;            this.ViewState[&amp;quot;ProductIDs&amp;quot;] = new List&amp;lt;int&amp;gt;();&lt;br /&gt;        }&lt;br /&gt;        return this.ViewState[&amp;quot;ProductIDs&amp;quot;] as List&amp;lt;int&amp;gt;;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private List&amp;lt;string&amp;gt; CustomerIDs&lt;br /&gt;{&lt;br /&gt;    get&lt;br /&gt;    {&lt;br /&gt;        if (this.ViewState[&amp;quot;CustomerIDs&amp;quot;] == null)&lt;br /&gt;        {&lt;br /&gt;            this.ViewState[&amp;quot;CustomerIDs&amp;quot;] = new List&amp;lt;string&amp;gt;();&lt;br /&gt;        }&lt;br /&gt;        return this.ViewState[&amp;quot;CustomerIDs&amp;quot;] as List&amp;lt;string&amp;gt;;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    if (!IsPostBack)&lt;br /&gt;    {&lt;br /&gt;        BindGrid(gvProducts, &amp;quot;Products&amp;quot;);&lt;br /&gt;        BindGrid(gvCustomers, &amp;quot;Customers&amp;quot;);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void gvProducts_PageIndexChanging(object sender, GridViewPageEventArgs e)&lt;br /&gt;{&lt;br /&gt;    foreach (GridViewRow gvr in gvProducts.Rows)&lt;br /&gt;    {&lt;br /&gt;        CheckBox chkSelect = gvr.FindControl(&amp;quot;chkSelect&amp;quot;) as CheckBox;&lt;br /&gt;        if (chkSelect != null)&lt;br /&gt;        {&lt;br /&gt;            int productID = Convert.ToInt32(gvProducts.DataKeys[gvr.RowIndex][&amp;quot;ProductID&amp;quot;]);&lt;br /&gt;            if (chkSelect.Checked &amp;amp;&amp;amp; !this.ProductIDs.Contains(productID))&lt;br /&gt;            {&lt;br /&gt;                this.ProductIDs.Add(productID);&lt;br /&gt;            }&lt;br /&gt;            else if (!chkSelect.Checked &amp;amp;&amp;amp; this.ProductIDs.Contains(productID))&lt;br /&gt;            {&lt;br /&gt;                this.ProductIDs.Remove(productID);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    gvProducts.PageIndex = e.NewPageIndex;&lt;br /&gt;    BindGrid(gvProducts, &amp;quot;Products&amp;quot;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void gvProducts_RowDataBound(object sender, GridViewRowEventArgs e)&lt;br /&gt;{&lt;br /&gt;    GridViewRow gvr = e.Row;&lt;br /&gt;    if (gvr.RowType == DataControlRowType.DataRow)&lt;br /&gt;    {&lt;br /&gt;        CheckBox chkSelect = gvr.FindControl(&amp;quot;chkSelect&amp;quot;) as CheckBox;&lt;br /&gt;        if (chkSelect != null)&lt;br /&gt;        {&lt;br /&gt;            int productID = Convert.ToInt32(gvProducts.DataKeys[gvr.RowIndex][&amp;quot;ProductID&amp;quot;]);&lt;br /&gt;            chkSelect.Checked = this.ProductIDs.Contains(productID);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void gvCustomers_PageIndexChanging(object sender, GridViewPageEventArgs e)&lt;br /&gt;{&lt;br /&gt;    foreach (GridViewRow gvr in gvCustomers.Rows)&lt;br /&gt;    {&lt;br /&gt;        CheckBox chkSelect = gvr.FindControl(&amp;quot;chkSelect&amp;quot;) as CheckBox;&lt;br /&gt;        if (chkSelect != null)&lt;br /&gt;        {&lt;br /&gt;            string customerID = gvCustomers.DataKeys[gvr.RowIndex][&amp;quot;CustomerID&amp;quot;].ToString();&lt;br /&gt;            if (chkSelect.Checked &amp;amp;&amp;amp; !this.CustomerIDs.Contains(customerID))&lt;br /&gt;            {&lt;br /&gt;                this.CustomerIDs.Add(customerID);&lt;br /&gt;            }&lt;br /&gt;            else if (!chkSelect.Checked &amp;amp;&amp;amp; this.CustomerIDs.Contains(customerID))&lt;br /&gt;            {&lt;br /&gt;                this.CustomerIDs.Remove(customerID);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    gvCustomers.PageIndex = e.NewPageIndex;&lt;br /&gt;    BindGrid(gvCustomers, &amp;quot;Customers&amp;quot;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void gvCustomers_RowDataBound(object sender, GridViewRowEventArgs e)&lt;br /&gt;{&lt;br /&gt;    GridViewRow gvr = e.Row;&lt;br /&gt;    if (gvr.RowType == DataControlRowType.DataRow)&lt;br /&gt;    {&lt;br /&gt;        CheckBox chkSelect = gvr.FindControl(&amp;quot;chkSelect&amp;quot;) as CheckBox;&lt;br /&gt;        if (chkSelect != null)&lt;br /&gt;        {&lt;br /&gt;            string customerID = gvCustomers.DataKeys[gvr.RowIndex][&amp;quot;CustomerID&amp;quot;].ToString();&lt;br /&gt;            chkSelect.Checked = this.CustomerIDs.Contains(customerID);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private DataTable PopulateData(string tableName)&lt;br /&gt;{&lt;br /&gt;    DataTable dt = new DataTable();&lt;br /&gt;    using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[&amp;quot;NorthwindConnectionString&amp;quot;].ConnectionString))&lt;br /&gt;    {&lt;br /&gt;        string sql = String.Format(&amp;quot;SELECT * FROM {0}&amp;quot;, tableName);&lt;br /&gt;        using (SqlDataAdapter adap = new SqlDataAdapter(sql, conn))&lt;br /&gt;        {&lt;br /&gt;            adap.Fill(dt);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    return dt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private void BindGrid(GridView gvTemp, string tableName)&lt;br /&gt;{&lt;br /&gt;    gvTemp.DataSource = PopulateData(tableName);&lt;br /&gt;    gvTemp.DataBind();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Happy Coding!&lt;br /&gt;&lt;br /&gt;P.S: Database in use is Northwind Sample Database.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-7454006716829230492?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/7454006716829230492/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2010/12/maintaining-checkbox-state-of-multiple.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/7454006716829230492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/7454006716829230492'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2010/12/maintaining-checkbox-state-of-multiple.html' title='Maintaining CheckBox State of multiple GridViews'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-3542418707227386989</id><published>2010-12-07T11:03:00.003+05:30</published><updated>2010-12-07T11:06:43.614+05:30</updated><title type='text'>Insert Arabic Words into Database</title><content type='html'>Often at forums.asp.net we come across the problem that occurs while inserting foreign language to the database. Supopose I wanted to insert 'اتصالات' to a table named 'table_test'. When I look at the entry at all I see is ?????. &lt;br /&gt;&lt;br /&gt;Why did this happen? Its because the field we enter the data needs to be having COLLATE Arabic.&lt;br /&gt;&lt;br /&gt;To understand that we must first understand what collation is.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;What is collation?&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Collation refers to a set of rules that determine how data is sorted and compared. &lt;br /&gt;Character data is sorted using rules that define the correct character sequence, &lt;br /&gt;with options for specifying &lt;br /&gt;1) case-sensitivity, &lt;br /&gt;2) accent marks, &lt;br /&gt;3) kana character types and &lt;br /&gt;4)character width.&lt;br /&gt;&lt;br /&gt;Case sensitivity&lt;br /&gt;&lt;br /&gt;If A and a, B and b, etc. are treated in the same way then it is case-insensitive. A computer treats A and a differently because it uses ASCII code to differentiate the input. The ASCII value of A is 65, while a is 97. The ASCII value of B is 66 and b is 98.&lt;br /&gt;&lt;br /&gt;Accent sensitivity&lt;br /&gt;&lt;br /&gt;If a and á, o and ó are treated in the same way, then it is accent-insensitive. A computer treats a and á differently because it uses ASCII code for differentiating the input. The ASCII value of a is 97 and áis 225. The ASCII value of o is 111 and ó is 243.&lt;br /&gt;&lt;br /&gt;Kana Sensitivity&lt;br /&gt;&lt;br /&gt;When Japanese kana characters Hiragana and Katakana are treated differently, it is called Kana sensitive. &lt;br /&gt;&lt;br /&gt;Width sensitivity&lt;br /&gt;&lt;br /&gt;When a single-byte character (half-width) and the same character when represented as a double-byte character (full-width) are treated differently then it is width sensitive.&lt;/blockquote&gt;&lt;br /&gt;Now we have identified the problem. Lets try to solve it using an example.&lt;br /&gt;In this example I am saving a textbox value to database on the click of a button.&lt;br /&gt;&lt;br /&gt;Suppose I have a table named table_test with two columns&lt;br /&gt;1. [myid] int auto&lt;br /&gt;2. [mytext] nvarchar(50)&lt;br /&gt;&lt;br /&gt;I want to enter the arabic word to the field mytext.&lt;br /&gt;&lt;br /&gt;Step1&lt;br /&gt;At Database provide collate to the field on which we want to insert the arabic word&lt;br /&gt;&lt;pre class="brush:sql"&gt;ALTER TABLE test_table&lt;br /&gt;ALTER COLUMN mytext VARCHAR(50) COLLATE Arabic_CI_AI&lt;br /&gt;&lt;/pre&gt;Step 2&lt;br /&gt;&lt;pre class="brush:csharp"&gt;protected void myButton_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["forums_ConnectionString"].ConnectionString))&lt;br /&gt;    {&lt;br /&gt;        conn.Open();&lt;br /&gt;        string sql = String.Format("INSERT INTO test_table (mytext) VALUES (N'{0}')",&lt;br /&gt;            mytext.Text.Trim());&lt;br /&gt;        using (SqlCommand cmd = new SqlCommand(sql, conn))&lt;br /&gt;        {&lt;br /&gt;            cmd.ExecuteNonQuery();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Please note that I have put N' before the value.&lt;br /&gt;Read the article &lt;a href="http://databases.aspfaq.com/general/why-do-some-sql-strings-have-an-n-prefix.html" target="_blank"&gt;Why do some SQL strings have an 'N' prefix?&lt;/a&gt; if you want to know its significance.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-3542418707227386989?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/3542418707227386989/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2010/12/insert-arabic-words-into-database.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/3542418707227386989'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/3542418707227386989'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2010/12/insert-arabic-words-into-database.html' title='Insert Arabic Words into Database'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-1497432109213488113</id><published>2010-11-16T10:16:00.004+05:30</published><updated>2010-11-16T11:14:10.561+05:30</updated><title type='text'>Prevent site from getting loaded on iframe</title><content type='html'>What if somebody loads your obfuscated fancy javascript or AJAX methods to drive traffic to their site utilising your bandwidth? Here is a simple solution in javascript.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:javascript"&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;//&amp;lt;![CDATA[&lt;br /&gt;    if (window.top !== window.self) {&lt;br /&gt;        document.write = &amp;quot;&amp;quot;;&lt;br /&gt;        window.top.location = window.self.location;&lt;br /&gt;        setTimeout(function () {&lt;br /&gt;            document.body.innerHTML = &amp;#39;&amp;#39;;&lt;br /&gt;        }, 1);&lt;br /&gt;        window.self.onload = function (evt) {&lt;br /&gt;            document.body.innerHTML = &amp;#39;&amp;#39;;&lt;br /&gt;        }; &lt;br /&gt;    }&lt;br /&gt;//]]&amp;gt;&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Paste that javascript snippet inside your head tag of your html.&lt;br /&gt;Twitter(Dustin Diaz) uses that at the &lt;a href="http://twitter.com/about/resources/widgets/widget_profile"&gt;Twitter Profile Widget Page&lt;/a&gt;. :(&lt;br /&gt;I found it the hard way (lol). Way to go Dustin!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-1497432109213488113?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/1497432109213488113/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2010/11/prevent-your-site-from-getting-loaded.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/1497432109213488113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/1497432109213488113'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2010/11/prevent-your-site-from-getting-loaded.html' title='Prevent site from getting loaded on iframe'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-464776931925859118</id><published>2010-11-15T11:36:00.000+05:30</published><updated>2010-11-15T11:36:04.261+05:30</updated><title type='text'>HTML Encode Decode in Javascript/jQuery</title><content type='html'>Last day, I had a resolute and unyielding need to HTML Decode a string.&lt;br /&gt;I saw many solutions but was not satisfied.&lt;br /&gt;Then I found the &lt;a href="http://stackoverflow.com/questions/1219860/javascript-jquery-html-encoding"&gt;StackOverFlow reference&lt;/a&gt; which is the most optimal solution I have seen till date. Just pasting it here for easy reference. &lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:html"&gt;&lt;br /&gt;function htmlEncode(value){ &lt;br /&gt;  return $('&amp;lt;div/&amp;gt;').text(value).html(); &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;function htmlDecode(value){ &lt;br /&gt;  return $('&amp;lt;div/&amp;gt;').html(value).text(); &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Did I say jQuery? I sure did say optimal :P&lt;br /&gt;Happy Coding!&lt;br /&gt;&lt;br /&gt;Dependency: jQuery&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-464776931925859118?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/464776931925859118/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2010/11/html-encode-decode-in-javascriptjquery.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/464776931925859118'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/464776931925859118'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2010/11/html-encode-decode-in-javascriptjquery.html' title='HTML Encode Decode in Javascript/jQuery'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-3678071981011973487</id><published>2010-11-10T15:32:00.003+05:30</published><updated>2010-11-10T15:35:44.295+05:30</updated><title type='text'>Different ways to create a DataTable and set Schema</title><content type='html'>Was hanging out StackOverflow and I saw &lt;a href="http://stackoverflow.com/questions/441023/fastest-way-to-convert-datatable-to-generic-list#441059"&gt;Marc Gravell initializing the DataTable&lt;/a&gt; in a simpler and cleaner way. Here goes &lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:c-sharp"&gt;DataTable dataTable = new DataTable&lt;br /&gt;{&lt;br /&gt;    Columns = {&lt;br /&gt;        {"ID", typeof(int)},&lt;br /&gt;        {"Name", typeof(string)},&lt;br /&gt;        "Location"&lt;br /&gt;    },&lt;br /&gt;    TableName="NaveenTest"&lt;br /&gt;};&lt;br /&gt;dataTable.Rows.Add(1, "Naveen", "Coder");&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;blockquote&gt;Please note that if you don't specify the type it will automatically be converted to string. See how "Location" is initialised&lt;br /&gt;&lt;/blockquote&gt;And my old method&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:c-sharp"&gt;DataTable dtOld = new DataTable("NaveenTest");&lt;br /&gt;dtOld.Columns.Add("MyID", typeof(int));&lt;br /&gt;dtOld.Columns.Add("Name");&lt;br /&gt;dtOld.Columns.Add("Location");&lt;br /&gt;DataRow drOld = new DataRow();&lt;br /&gt;drOld[0] = 1;&lt;br /&gt;drOld[1] = "Naveen";&lt;br /&gt;drOld[2] = "Coder";&lt;br /&gt;dtOld.Rows.Add(drOld);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Aaarghhh...&lt;br /&gt;&lt;br /&gt;A lot cleaner!&lt;br /&gt;What do you say?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-3678071981011973487?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/3678071981011973487/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2010/11/different-ways-to-create-datatable-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/3678071981011973487'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/3678071981011973487'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2010/11/different-ways-to-create-datatable-and.html' title='Different ways to create a DataTable and set Schema'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-4698266886015925121</id><published>2009-12-22T14:25:00.004+05:30</published><updated>2010-11-08T19:30:40.449+05:30</updated><title type='text'>Gray Scale images in all Browsers</title><content type='html'>Its been a while since I blogged on anything.&lt;br /&gt;Today I came across a post at forums.asp.net: &lt;a href="http://forums.asp.net/t/1506347.aspx"&gt;change color image to gray scale&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;GrayScale - Converts the colors of the object to 256 shades of gray.&lt;/blockquote&gt;An example will be&lt;br /&gt;&lt;br /&gt;&lt;img src="http://sites.google.com/site/fun2code/Home/naveenj-org-to-gray.jpg" /&gt;&lt;br /&gt;&lt;br /&gt;Since GrayScale filter is a filter present in the Internet Explorer, &lt;br /&gt;we can achieve this result in IE simply by using the css property&lt;br /&gt;&lt;pre class="brush:css"&gt;.greyscale_filter{ &lt;br /&gt; filter: gray;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;or&lt;br /&gt;&lt;pre class="brush:css"&gt;.greyscale_filter{&lt;br /&gt; -ms-filter: "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";&lt;br /&gt; filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Here the second method is more advanced and must have Internet Explorer 5.5 or later to work properly.&lt;br /&gt;&lt;br /&gt;There are number of filters in IE apart from GrayScale. Here are some lists&lt;br /&gt;&lt;br /&gt;1. &lt;a href="http://msdn.microsoft.com/en-us/library/ms673539(VS.85).aspx"&gt;Static filters by MSDN&lt;/a&gt;&lt;br /&gt;2. &lt;a href="http://www.ssi-developer.net/css/visual-filters.shtml"&gt;CSS Visual Filters&lt;/a&gt;&lt;br /&gt;3. &lt;a href="http://www.javascriptkit.com/filters/index.shtml"&gt;IE Multimedia filters reference&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This is the case with Internet Explorer.&lt;br /&gt;Now the big question.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Why does not the GrayScale filter work with browsers like Chrome, Firefox and Safari?&lt;br /&gt;Simple. The filter is specific to IE only.&lt;/blockquote&gt;&lt;br /&gt;While I was searching through the internet for a good solution, I found &lt;a href="http://stackoverflow.com/questions/878786/css-do-non-ie-browsers-support-the-filter-attribute#878795"&gt;this at SO&lt;/a&gt;&lt;br /&gt;There I discovered a wonderful javascript coder named &lt;a href="http://james.padolsey.com/"&gt;James Padolsey&lt;/a&gt; who is just 19!&lt;br /&gt;&lt;br /&gt;Copied his GrayScale.js which according to James Padolsey is &lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;b&gt;Grayscale.js is an experimental attempt to emulate Microsoft's &lt;br /&gt;proprietary 'grayscale' filter (available in most IE versions).&lt;/b&gt;&lt;/blockquote&gt;&lt;br /&gt;And it worked like a charm.&lt;br /&gt;&lt;br /&gt;So here are the steps involved in achieving the hover effect&lt;br /&gt;&lt;br /&gt;1. Grab the GrayScale.js from James Padolsey's site. (&lt;a href="http://james.padolsey.com/demos/grayscale/grayscale.js"&gt;The link is here&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;2. Add refernce to jQuery. Please note that jQuery is not required for grayscale.js - it's only used for this demo&lt;br /&gt;Its better to refer jQuery like this (&lt;a href="http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/"&gt;Read Dave Ward ka Encosia on this topic&lt;/a&gt;)&lt;br /&gt;&lt;pre class="brush:html"&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;  &lt;/pre&gt;than&lt;br /&gt;&lt;pre class="brush:html"&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/js/jQuery.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;  &lt;/pre&gt;3. Add a small javascript snippet like this&lt;br /&gt;&lt;pre class="brush:jscript"&gt;$(document).ready(function(){&lt;br /&gt;     $('img.greyonhover').hover(function(){&lt;br /&gt;    grayscale(this);&lt;br /&gt;   }, function(){&lt;br /&gt;    grayscale.reset(this);&lt;br /&gt;   })&lt;br /&gt;  });&lt;br /&gt;  &lt;/pre&gt;4. Assign the class="greyonhover" for the image you want to implement grayscale effect onhover &lt;br /&gt;&lt;pre class="brush:html"&gt;&amp;lt;img class=&amp;quot;greyonhover&amp;quot; src=&amp;quot;images/naveenj-thumb.jpg&amp;quot; /&amp;gt;&lt;br /&gt;  &lt;/pre&gt;&lt;br /&gt;This is all you have to do to achieve greying effect on hover.  &lt;a href="http://sites.google.com/site/fun2code/Home/grayscaling.zip"&gt;Download Source Code(9k)&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-4698266886015925121?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/4698266886015925121/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2009/12/gray-scale-images-in-all-browsers.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/4698266886015925121'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/4698266886015925121'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2009/12/gray-scale-images-in-all-browsers.html' title='Gray Scale images in all Browsers'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-1042968033133456316</id><published>2009-10-21T12:49:00.005+05:30</published><updated>2010-11-07T15:24:56.784+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='row selection'/><category scheme='http://www.blogger.com/atom/ns#' term='Invalid postback or callback argument'/><category scheme='http://www.blogger.com/atom/ns#' term='select button'/><category scheme='http://www.blogger.com/atom/ns#' term='gridviewrow'/><category scheme='http://www.blogger.com/atom/ns#' term='selectable row'/><category scheme='http://www.blogger.com/atom/ns#' term='eventvalidation false'/><category scheme='http://www.blogger.com/atom/ns#' term='__doPostBack object expected'/><category scheme='http://www.blogger.com/atom/ns#' term='gridview'/><category scheme='http://www.blogger.com/atom/ns#' term='rowclick'/><title type='text'>Selectable GridViewRow using Javascript</title><content type='html'>Hope you have read my post about &lt;a href="http://fun2code.blogspot.com/2009/10/gridviewrow-as-select-button.html"&gt;Selectable GridViewRow&lt;/a&gt;&lt;br /&gt;If you haven't done that please do that before you proceed further.&lt;br /&gt;This is a sort of sequel to that post.&lt;br /&gt;&lt;br /&gt;Here I am making a GridView Selectable using &lt;span style="font-weight:bold;"&gt;__doPostBack(...)&lt;/span&gt; function&lt;br /&gt;&lt;br /&gt;Suppose you have a GridView populated from the &lt;span style="font-weight:bold;"&gt;Products&lt;/span&gt; table of the &lt;span style="font-weight:bold;"&gt;NorthWind &lt;/span&gt;Database.&lt;br /&gt;&lt;br /&gt;So the ASPX looks like this&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:html"&gt;&amp;lt;asp:GridView ID=&amp;quot;gvwProducts&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;AutoGenerateColumns=&amp;quot;False&amp;quot; &lt;br /&gt;DataKeyNames=&amp;quot;ProductID&amp;quot;&lt;br /&gt;DataSourceID=&amp;quot;sdsProducts&amp;quot;&lt;br /&gt;OnRowDataBound=&amp;quot;gvwProducts_RowDataBound&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;Columns&amp;gt;&lt;br /&gt;&amp;lt;asp:TemplateField HeaderText=&amp;quot;Contact Name&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;asp:Label ID=&amp;quot;lblProductName&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;Text='&amp;lt;%#Eval(&amp;quot;ProductName&amp;quot;) %&amp;gt;'&amp;gt;&lt;br /&gt;&amp;lt;/asp:Label&amp;gt;&lt;br /&gt;&amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;&amp;lt;asp:TemplateField HeaderText=&amp;quot;Stock&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;asp:Label ID=&amp;quot;lblunitsInStock&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;Text='&amp;lt;%#Eval(&amp;quot;UnitsInStock&amp;quot;) %&amp;gt;'&amp;gt;&lt;br /&gt;&amp;lt;/asp:Label&amp;gt;&lt;br /&gt;&amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/Columns&amp;gt;&lt;br /&gt;&amp;lt;SelectedRowStyle ForeColor=&amp;quot;Green&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;HeaderStyle BackColor=&amp;quot;#507CD1&amp;quot; Font-Bold=&amp;quot;True&amp;quot; ForeColor=&amp;quot;White&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;&amp;lt;asp:SqlDataSource ID=&amp;quot;sdsProducts&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;ConnectionString=&amp;quot;&amp;lt;%$ ConnectionStrings:NorthwindConnectionString %&amp;gt;&amp;quot;&lt;br /&gt;SelectCommand=&amp;quot;SELECT ProductID, ProductName, UnitsInStock FROM Products&amp;quot;&lt;br /&gt;SelectCommandType=&amp;quot;Text&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/asp:SqlDataSource&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now on &lt;span style="font-weight:bold;"&gt;RowDataBound &lt;/span&gt;lets set the click attribute for selectable row.&lt;br /&gt;You can also use RowCreated for this.&lt;br /&gt;Note that we are also giving some fancy color changes in onmouseover and onmouseout events.&lt;br /&gt;Discard them if you dont want color changes.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:c-sharp"&gt;protected void gvwProducts_RowDataBound(object sender, GridViewRowEventArgs e)&lt;br /&gt;{&lt;br /&gt;if (e.Row.RowType == DataControlRowType.DataRow)&lt;br /&gt;{&lt;br /&gt;//e.Row.Attributes["onmouseover"] = "this.style.color='DodgerBlue';this.style.cursor='hand';";&lt;br /&gt;e.Row.Attributes["onmouseover"] = "javascript:return ChangeRowColor('m_over', this.style)";&lt;br /&gt;//e.Row.Attributes["onmouseout"] = "this.style.color='Black';";&lt;br /&gt;e.Row.Attributes["onmouseout"] = "javascript:return ChangeRowColor('m_out', this.style)";&lt;br /&gt;e.Row.Attributes["onclick"] = "javascript:return __doPostBack('" + gvwProducts.ClientID.Replace('_','$') + "', 'Select$" + e.Row.RowIndex + "');";&lt;br /&gt;e.Row.ToolTip = "Click on the row to select it";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now register these postbacks for event validation at Page_Render to avoid&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;br /&gt;System.ArgumentException: Invalid postback or callback argument.  Event validation is enabled using &lt;pages enableEventValidation="true"/&gt; in configuration or &lt;%@ Page EnableEventValidation="true" %&gt; in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:c-sharp"&gt;protected override void Render(HtmlTextWriter writer)&lt;br /&gt;{&lt;br /&gt;// .NET will refuse to accept "unknown" postbacks for security reasons. &lt;br /&gt;// Because of this we have to register all possible callbacks&lt;br /&gt;// This must be done in Render, hence the override&lt;br /&gt;for (int i = 0; i &lt; gvwProducts.Rows.Count; i++)&lt;br /&gt;{&lt;br /&gt;Page.ClientScript.RegisterForEventValidation(new System.Web.UI.PostBackOptions(this.gvwProducts, "Select$" + i.ToString()));&lt;br /&gt;}&lt;br /&gt;// Do the standard rendering stuff&lt;br /&gt;base.Render(writer);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Now compare the RowDataBound event to first example and you note some changes inthe way the row attributes for onmouseover and onmouseout are set.(Check the commented lines in the RowDataBound event)What we do here is to set a foreground color "Green" to the Selected Row and persists that coloronmouseout and onmouseover of the selected row.Inorder to achieve that, place this javascript function on the page.&lt;pre class="brush:javascript"&gt;function ChangeRowColor(eventtype, rowStyle){&lt;br /&gt;if(rowStyle.color.toLowerCase() != "green"){&lt;br /&gt;if(eventtype == "m_over"){&lt;br /&gt;rowStyle.color='DodgerBlue';&lt;br /&gt;rowStyle.cursor='pointer';&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;rowStyle.color='Black';&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;rowStyle.cursor='default';&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Now some developers may get the &lt;blockquote&gt;__doPostBack(...) object required &lt;/blockquote&gt;To circumvent this error place these on the ASPX PageTwo Hidden Fields&lt;pre class="brush:html"&gt;&amp;lt;input type =&amp;quot;hidden&amp;quot; name =&amp;quot;__EVENTTARGET&amp;quot; value =&amp;quot;&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;input type =&amp;quot;hidden&amp;quot; name =&amp;quot;__EVENTARGUMENT&amp;quot; value =&amp;quot;&amp;quot; /&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Javascript Function&lt;pre class="brush:javascript"&gt;//&lt;![CDATA[&lt;br /&gt;var theForm = document.forms['aspnetForm'];&lt;br /&gt;if (!theForm) {&lt;br /&gt;theForm = (!document.aspnetForm)?document.forms[0] : document.aspnetForm;&lt;br /&gt;}&lt;br /&gt;function __doPostBack(eventTarget, eventArgument) {&lt;br /&gt;if (!theForm.onsubmit || (theForm.onsubmit() != false)) {&lt;br /&gt;theForm.__EVENTTARGET.value = eventTarget;&lt;br /&gt;theForm.__EVENTARGUMENT.value = eventArgument;&lt;br /&gt;theForm.submit();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;//]]&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Happy Coding!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-1042968033133456316?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/1042968033133456316/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2009/10/selectable-gridviewrow-using-javascript.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/1042968033133456316'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/1042968033133456316'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2009/10/selectable-gridviewrow-using-javascript.html' title='Selectable GridViewRow using Javascript'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-3659615639960610040</id><published>2009-10-19T21:12:00.009+05:30</published><updated>2010-11-07T16:48:54.830+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='row selection'/><category scheme='http://www.blogger.com/atom/ns#' term='Invalid postback or callback argument'/><category scheme='http://www.blogger.com/atom/ns#' term='select button'/><category scheme='http://www.blogger.com/atom/ns#' term='gridviewrow'/><category scheme='http://www.blogger.com/atom/ns#' term='selectable row'/><category scheme='http://www.blogger.com/atom/ns#' term='eventvalidation false'/><category scheme='http://www.blogger.com/atom/ns#' term='__doPostBack object expected'/><category scheme='http://www.blogger.com/atom/ns#' term='gridview'/><category scheme='http://www.blogger.com/atom/ns#' term='rowclick'/><title type='text'>Selectable GridViewRow</title><content type='html'>I have always found using Select Button in GridView to select a row cumbersome.&lt;br /&gt;It would be always better to click anywhere on the GridViewRow and Select the row.&lt;br /&gt;&lt;br /&gt;Here's a snippet on how to do it.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;On RowDataBound&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:c-sharp"&gt;protected void gvwProducts_RowDataBound(object sender, GridViewRowEventArgs e)&lt;br /&gt;{&lt;br /&gt;if (e.Row.RowType == DataControlRowType.DataRow)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;e.Row.Attributes["onmouseover"] = "this.style.color='DodgerBlue';this.style.cursor='hand';";&lt;br /&gt;e.Row.Attributes["onmouseout"] = "this.style.color='Black';";&lt;br /&gt;e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gvwProducts, "Select$" + e.Row.RowIndex);&lt;br /&gt;e.Row.ToolTip = "Click on the row to select it";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now if we run the code and click on the row we will get this error&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;br /&gt;System.ArgumentException: Invalid postback or callback argument.  &lt;br /&gt;Event validation is enabled using &lt;pages enableEventValidation="true"/&gt; in configuration &lt;br /&gt;or &lt;%@ Page EnableEventValidation="true" %&gt; in a page.  &lt;br /&gt;For security purposes, this feature verifies that arguments to postback or callback events originate &lt;br /&gt;from the server control that originally rendered them.  &lt;br /&gt;If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method &lt;br /&gt;in order to register the postback or callback data for validation.&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;To avoid this we override the Page's Render Event.&lt;br /&gt;Inside that event we register an event reference for validation on each GridViewRow&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;The overridden Page Render&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:c-sharp"&gt;protected override void Render(HtmlTextWriter writer)&lt;br /&gt;{&lt;br /&gt;// .NET will refuse to accept "unknown" postbacks for security reasons. &lt;br /&gt;// Because of this we have to register all possible callbacks&lt;br /&gt;// This must be done in Render, hence the override&lt;br /&gt;for (int i = 0; i &lt; gvwProducts.Rows.Count; i++)&lt;br /&gt;{&lt;br /&gt;Page.ClientScript.RegisterForEventValidation(new System.Web.UI.PostBackOptions(gvwProducts, "Select$" + i.ToString()));&lt;br /&gt;}&lt;br /&gt;// Do the standard rendering stuff&lt;br /&gt;base.Render(writer);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Here I am posting the ASPX markup of the GridView also&lt;span style="font-weight:bold;"&gt;The ASPX&lt;/span&gt;&lt;pre class="brush:xhtml"&gt;&amp;lt;asp:GridView ID=&amp;quot;gvwProducts&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;AutoGenerateColumns=&amp;quot;False&amp;quot; &lt;br /&gt;DataKeyNames=&amp;quot;ProductID&amp;quot;&lt;br /&gt;DataSourceID=&amp;quot;sdsProducts&amp;quot;&lt;br /&gt;OnRowDataBound=&amp;quot;gvwProducts_RowDataBound&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;Columns&amp;gt;&lt;br /&gt;&amp;lt;asp:TemplateField HeaderText=&amp;quot;Contact Name&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;asp:Label ID=&amp;quot;lblProductName&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;Text='&amp;lt;%#Eval(&amp;quot;ProductName&amp;quot;) %&amp;gt;'&amp;gt;&lt;br /&gt;&amp;lt;/asp:Label&amp;gt;&lt;br /&gt;&amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;&amp;lt;asp:TemplateField HeaderText=&amp;quot;Stock&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;asp:Label ID=&amp;quot;lblunitsInStock&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;Text='&amp;lt;%#Eval(&amp;quot;UnitsInStock&amp;quot;) %&amp;gt;'&amp;gt;&lt;br /&gt;&amp;lt;/asp:Label&amp;gt;&lt;br /&gt;&amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/Columns&amp;gt;&lt;br /&gt;&amp;lt;SelectedRowStyle BackColor=&amp;quot;#D1DDF1&amp;quot; Font-Bold=&amp;quot;True&amp;quot; ForeColor=&amp;quot;#333333&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;HeaderStyle BackColor=&amp;quot;#507CD1&amp;quot; Font-Bold=&amp;quot;True&amp;quot; ForeColor=&amp;quot;White&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;&amp;lt;asp:SqlDataSource ID=&amp;quot;sdsProducts&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;ConnectionString=&amp;quot;&amp;lt;%$ ConnectionStrings:NorthwindConnectionString %&amp;gt;&amp;quot;&lt;br /&gt;SelectCommand=&amp;quot;SELECT ProductID, ProductName, UnitsInStock FROM Products&amp;quot;&lt;br /&gt;SelectCommandType=&amp;quot;Text&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/asp:SqlDataSource&amp;gt;&lt;br /&gt;&lt;/pre&gt;Just paste the last xml snippet on ASPX and first two code snippets on cs page.Change the connectionstring to the one you have and run the code to see the result.We are not finished yetFrom time to time, some developers will experience the "__doPostBack object expected" error in the page Postback.This occurs at the second time we try to fire the row click eventThe Reason&lt;blockquote&gt;We add onclick feature for GridView in the RowDataBound event using &lt;span style="font-weight:bold;"&gt;ClientScript.GetPostBackClientHyperlink(...)&lt;/span&gt;But RowDataBound event gets fired only the first time(at !IsPostBack). This creates the &lt;span style="font-weight:bold;"&gt;__doPostBack()&lt;/span&gt; function when the page is first time loaded.Now from the second time onwards(at IsPostBack) RowDataBound doesn't get fired.So no &lt;span style="font-weight:bold;"&gt;ClientScript.GetPostBackClientHyperlink(...)&lt;/span&gt; is called and no  __doPostBack() function is created&lt;/blockquote&gt;The solution. Just place this line under Page_Load event&lt;pre class="brush:c-sharp"&gt;&lt;br /&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;ClientScript.GetPostBackClientHyperlink(this, "");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Happy Coding!For Better understanding please read &lt;a href="http://fun2code.blogspot.com/2009/10/selectable-gridviewrow-using-javascript.html"&gt;Selectable GridViewRow using JavaScript&lt;/a&gt;Points to Note:1. I have given a &lt;span style="font-weight:bold;"&gt;SelectedRowStyle &lt;/span&gt;to show that the row is actually selected by giving it a different color.2. The table used is &lt;span style="font-weight:bold;"&gt;Products &lt;/span&gt;from Microsoft's Sample DataBase &lt;span style="font-weight:bold;"&gt;Northwind&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-3659615639960610040?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/3659615639960610040/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2009/10/gridviewrow-as-select-button.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/3659615639960610040'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/3659615639960610040'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2009/10/gridviewrow-as-select-button.html' title='Selectable GridViewRow'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-6208628106492245528</id><published>2009-08-27T18:12:00.004+05:30</published><updated>2009-10-22T16:57:13.569+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='gridview sorting paging'/><title type='text'>Sorting and Paging a GridView</title><content type='html'>Sorting can be tricky. But maintaining the sort order on paging is trickier&lt;br /&gt;Here is a sample code for that&lt;br /&gt;&lt;br /&gt;DataBase used is Northwind.&lt;br /&gt;Table used is Products.&lt;br /&gt;&lt;br /&gt;The ASPX&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="xhtml"&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;asp:GridView ID=&amp;quot;GridView1&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;                AllowPaging=&amp;quot;true&amp;quot;&lt;br /&gt;                AllowSorting=&amp;quot;true&amp;quot;&lt;br /&gt;                AutoGenerateColumns=&amp;quot;false&amp;quot;&lt;br /&gt;                DataKeyNames=&amp;quot;ProductID&amp;quot;&lt;br /&gt;                PageSize=&amp;quot;10&amp;quot;&lt;br /&gt;                OnPageIndexChanging=&amp;quot;GridView1_PageIndexChanging&amp;quot;&lt;br /&gt;                OnSorting=&amp;quot;GridView1_Sorting&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;Columns&amp;gt;&lt;br /&gt;        &amp;lt;asp:TemplateField HeaderText=&amp;quot;ID&amp;quot; SortExpression=&amp;quot;ProductID&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;                &amp;lt;asp:Label ID=&amp;quot;lblProductID&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;                            Text='&amp;lt;%#Eval(&amp;quot;ProductID&amp;quot;) %&amp;gt;'&amp;gt;&lt;br /&gt;                &amp;lt;/asp:Label&amp;gt;&lt;br /&gt;            &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;        &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;        &amp;lt;asp:TemplateField HeaderText=&amp;quot;Name&amp;quot; SortExpression=&amp;quot;ProductName&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;                &amp;lt;asp:Label ID=&amp;quot;lblProductName&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;                            Text='&amp;lt;%#Eval(&amp;quot;ProductName&amp;quot;) %&amp;gt;'&amp;gt;&lt;br /&gt;                &amp;lt;/asp:Label&amp;gt;&lt;br /&gt;            &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;        &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;        &amp;lt;asp:TemplateField HeaderText=&amp;quot;Stock&amp;quot; SortExpression=&amp;quot;UnitsInStock&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;                &amp;lt;asp:Label ID=&amp;quot;lblUnitsInStock&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;                            Text='&amp;lt;%#Eval(&amp;quot;UnitsInStock&amp;quot;) %&amp;gt;'&amp;gt;&lt;br /&gt;                &amp;lt;/asp:Label&amp;gt;&lt;br /&gt;            &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;        &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;    &amp;lt;/Columns&amp;gt;&lt;br /&gt;&amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The ASPX.CS&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="c-sharp"&gt;&lt;br /&gt;&lt;br /&gt;private const string ASCENDING = " ASC";&lt;br /&gt;private const string DESCENDING = " DESC";&lt;br /&gt;static private DataView dvProducts;&lt;br /&gt;&lt;br /&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    if (!IsPostBack)&lt;br /&gt;    {&lt;br /&gt;        dvProducts = new DataView(GetProductsFromDataTable());&lt;br /&gt;        BindGridView();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)&lt;br /&gt;{&lt;br /&gt;    string sortExpression = e.SortExpression;&lt;br /&gt;&lt;br /&gt;    if (GridViewSortDirection == SortDirection.Ascending)&lt;br /&gt;    {&lt;br /&gt;        GridViewSortDirection = SortDirection.Descending;&lt;br /&gt;        dvProducts.Sort = sortExpression + DESCENDING;&lt;br /&gt;        BindGridView();&lt;br /&gt;    }&lt;br /&gt;    else&lt;br /&gt;    {&lt;br /&gt;        GridViewSortDirection = SortDirection.Ascending;&lt;br /&gt;        dvProducts.Sort = sortExpression + ASCENDING;&lt;br /&gt;        BindGridView();&lt;br /&gt;    }   &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)&lt;br /&gt;{&lt;br /&gt;    GridView1.PageIndex = e.NewPageIndex;&lt;br /&gt;    BindGridView();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private void BindGridView()&lt;br /&gt;{&lt;br /&gt;    GridView1.DataSource = dvProducts;&lt;br /&gt;    GridView1.DataBind();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public SortDirection GridViewSortDirection&lt;br /&gt;{&lt;br /&gt;    get&lt;br /&gt;    {&lt;br /&gt;        if (ViewState["sortDirection"] == null)&lt;br /&gt;            ViewState["sortDirection"] = SortDirection.Ascending;&lt;br /&gt;&lt;br /&gt;        return (SortDirection)ViewState["sortDirection"];&lt;br /&gt;    }&lt;br /&gt;    set { ViewState["sortDirection"] = value; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private DataTable GetProductsFromDataTable()&lt;br /&gt;{&lt;br /&gt;    DataTable dtProductsTemp = new DataTable();&lt;br /&gt;    using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString))&lt;br /&gt;    {&lt;br /&gt;        using (SqlDataAdapter adapProducts = new SqlDataAdapter("Select * from Products", conn))&lt;br /&gt;        {&lt;br /&gt;            adapProducts.Fill(dtProductsTemp);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    return dtProductsTemp;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Extra namespace used&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="c-sharp"&gt;&lt;br /&gt;&lt;br /&gt;using System.Data.SqlClient;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-6208628106492245528?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/6208628106492245528/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2009/08/sorting-and-paging-gridview.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/6208628106492245528'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/6208628106492245528'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2009/08/sorting-and-paging-gridview.html' title='Sorting and Paging a GridView'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-141350710968131361</id><published>2009-07-18T16:51:00.012+05:30</published><updated>2009-10-05T17:01:41.160+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='repeater paging pageddatasource'/><title type='text'>Paging in Repeater</title><content type='html'>Heres a sample on how to implement Paging on a Repeater.&lt;br /&gt;&lt;br /&gt;The Output&lt;br /&gt;&lt;br /&gt;&lt;img style="cursor:pointer; cursor:hand;width: 478px; height: 328px;" src="http://sites.google.com/site/fun2code/Home/repeaterpaging.jpg" border="0" alt="" /&gt;&lt;br /&gt;&lt;br /&gt;The ASPX&lt;br /&gt;&lt;pre name="code" class="xhtml"&gt;&lt;br /&gt; &amp;lt;asp:Repeater ID=&amp;quot;rptrProducts&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;HeaderTemplate&amp;gt;&lt;br /&gt;            &amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;                &amp;lt;tr style=&amp;quot;background-color:Gray;&amp;quot;&amp;gt;&lt;br /&gt;                    &amp;lt;td&amp;gt;&lt;br /&gt;                        Product Name&lt;br /&gt;                    &amp;lt;/td&amp;gt;&lt;br /&gt;                    &amp;lt;td&amp;gt;&lt;br /&gt;                        Quantity Per Unit&lt;br /&gt;                    &amp;lt;/td&amp;gt;&lt;br /&gt;                    &amp;lt;td&amp;gt;&lt;br /&gt;                        Units On Order&lt;br /&gt;                    &amp;lt;/td&amp;gt;&lt;br /&gt;                    &amp;lt;td&amp;gt;&lt;br /&gt;                        Discontinued&lt;br /&gt;                    &amp;lt;/td&amp;gt;&lt;br /&gt;                &amp;lt;/tr&amp;gt;&lt;br /&gt;        &amp;lt;/HeaderTemplate&amp;gt;&lt;br /&gt;        &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;            &amp;lt;tr&amp;gt;&lt;br /&gt;                &amp;lt;td&amp;gt;&lt;br /&gt;                    &amp;lt;asp:Label ID=&amp;quot;lblProductName&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%#Eval(&amp;quot;ProductName&amp;quot;) %&amp;gt;'&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;br /&gt;                &amp;lt;/td&amp;gt;&lt;br /&gt;                &amp;lt;td&amp;gt;&lt;br /&gt;                    &amp;lt;asp:Label ID=&amp;quot;lblQuantityPerUnit&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%#Eval(&amp;quot;QuantityPerUnit&amp;quot;) %&amp;gt;'&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;br /&gt;                &amp;lt;/td&amp;gt;&lt;br /&gt;                &amp;lt;td&amp;gt;&lt;br /&gt;                    &amp;lt;asp:Label ID=&amp;quot;lblUnitsOnOrder&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%#Eval(&amp;quot;UnitsOnOrder&amp;quot;) %&amp;gt;'&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;br /&gt;                &amp;lt;/td&amp;gt;&lt;br /&gt;                &amp;lt;td&amp;gt;&lt;br /&gt;                    &amp;lt;asp:CheckBox ID=&amp;quot;chkDiscontinued&amp;quot; runat=&amp;quot;server&amp;quot; Checked='&amp;lt;%#Eval(&amp;quot;Discontinued&amp;quot;) %&amp;gt;'&lt;br /&gt;                        Enabled=&amp;quot;false&amp;quot; /&amp;gt;&lt;br /&gt;                &amp;lt;/td&amp;gt;&lt;br /&gt;            &amp;lt;/tr&amp;gt;&lt;br /&gt;        &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;    &amp;lt;/asp:Repeater&amp;gt;&lt;br /&gt;    &amp;lt;tr align=&amp;quot;right&amp;quot; style=&amp;quot;background-color:Gray;&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;td colspan=&amp;quot;4&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;asp:LinkButton ID=&amp;quot;lnkFirst&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;                            ForeColor=&amp;quot;Black&amp;quot;&lt;br /&gt;                            Text=&amp;quot;First&amp;quot; onclick=&amp;quot;lnkFirst_Click&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;/asp:LinkButton&amp;gt;&amp;amp;nbsp;&lt;br /&gt;            &amp;lt;asp:LinkButton ID=&amp;quot;lnkPrevious&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;                            ForeColor=&amp;quot;Black&amp;quot;&lt;br /&gt;                            Text=&amp;quot;Previous&amp;quot; &lt;br /&gt;                            OnClick=&amp;quot;lnkPrevious_Click&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;/asp:LinkButton&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&lt;br /&gt;            Now Showing Page&amp;amp;nbsp;&lt;br /&gt;            &amp;lt;asp:DropDownList ID=&amp;quot;ddlpageNumbers&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;                                AutoPostBack=&amp;quot;true&amp;quot; &lt;br /&gt;                                OnSelectedIndexChanged=&amp;quot;ddlpageNumbers_SelectedIndexChanged&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;/asp:DropDownList&amp;gt;&amp;amp;nbsp;of&amp;amp;nbsp;&lt;br /&gt;            &amp;lt;asp:Label ID=&amp;quot;lblTotalPages&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;/asp:Label&amp;gt;&amp;amp;nbsp;Pages.&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&lt;br /&gt;            &amp;lt;asp:LinkButton ID=&amp;quot;lnkNext&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;                            ForeColor=&amp;quot;Black&amp;quot;&lt;br /&gt;                            Text=&amp;quot;Next&amp;quot; onclick=&amp;quot;lnkNext_Click&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;/asp:LinkButton&amp;gt;&amp;amp;nbsp;&lt;br /&gt;            &amp;lt;asp:LinkButton ID=&amp;quot;lnkLast&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;                            ForeColor=&amp;quot;Black&amp;quot;&lt;br /&gt;                            Text=&amp;quot;Last&amp;quot; onclick=&amp;quot;lnkLast_Click&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;/asp:LinkButton&amp;gt;&lt;br /&gt;        &amp;lt;/td&amp;gt;&lt;br /&gt;    &amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The ASPX.CS&lt;br /&gt;&lt;pre name="code" class="csharp"&gt;&lt;br /&gt;public partial class Repeaters_Paging : System.Web.UI.Page&lt;br /&gt;{&lt;br /&gt;    #region "Local Variables and Declarations"&lt;br /&gt;&lt;br /&gt;    private const bool blnAllowPaging = true;&lt;br /&gt;    private const int iPageSize = 10;&lt;br /&gt;&lt;br /&gt;    private static PagedDataSource pgdProducts = new PagedDataSource();&lt;br /&gt;&lt;br /&gt;    #endregion&lt;br /&gt;        &lt;br /&gt;    #region "Page Load Event"&lt;br /&gt;&lt;br /&gt;    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!IsPostBack)&lt;br /&gt;        {&lt;br /&gt;            BindRepeater();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    #endregion&lt;br /&gt;&lt;br /&gt;    #region "Footer LinkButtons"&lt;br /&gt;&lt;br /&gt;    protected void lnkFirst_Click(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        ThisPageNumber = 0;&lt;br /&gt;        BindRepeater();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    protected void lnkPrevious_Click(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        --ThisPageNumber;&lt;br /&gt;        BindRepeater();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    protected void lnkNext_Click(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;        ++ThisPageNumber;&lt;br /&gt;        BindRepeater();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    protected void lnkLast_Click(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        ThisPageNumber = pgdProducts.PageCount - 1;&lt;br /&gt;        BindRepeater();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    #endregion&lt;br /&gt;&lt;br /&gt;    #region "Footer DropDownList"&lt;br /&gt;&lt;br /&gt;    protected void ddlpageNumbers_SelectedIndexChanged(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        ThisPageNumber = ddlpageNumbers.SelectedIndex;&lt;br /&gt;        BindRepeater();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    #endregion&lt;br /&gt;&lt;br /&gt;    #region "Custom Functions"&lt;br /&gt;&lt;br /&gt;    private void BindRepeater()&lt;br /&gt;    {&lt;br /&gt;        pgdProducts.AllowPaging = blnAllowPaging;&lt;br /&gt;        pgdProducts.PageSize = iPageSize;&lt;br /&gt;        pgdProducts.DataSource = GetProductsDataView();&lt;br /&gt;&lt;br /&gt;        pgdProducts.CurrentPageIndex = ThisPageNumber;&lt;br /&gt;        lblTotalPages.Text = pgdProducts.PageCount.ToString();&lt;br /&gt;        FillPagesDropDownList(pgdProducts.PageCount);&lt;br /&gt;&lt;br /&gt;        lnkFirst.Enabled = !pgdProducts.IsFirstPage;&lt;br /&gt;        lnkPrevious.Enabled = !pgdProducts.IsFirstPage;&lt;br /&gt;        lnkNext.Enabled = !pgdProducts.IsLastPage;&lt;br /&gt;        lnkLast.Enabled = !pgdProducts.IsLastPage;&lt;br /&gt;        ddlpageNumbers.SelectedIndex = pgdProducts.CurrentPageIndex; &lt;br /&gt;&lt;br /&gt;        rptrProducts.DataSource = pgdProducts;&lt;br /&gt;        rptrProducts.DataBind();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private DataView GetProductsDataView()&lt;br /&gt;    {&lt;br /&gt;        DataTable dtProductsTemp = new DataTable();&lt;br /&gt;        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString))&lt;br /&gt;        {&lt;br /&gt;            using (SqlDataAdapter adapProducts = new SqlDataAdapter("Select * from Products", conn))&lt;br /&gt;            {&lt;br /&gt;                adapProducts.Fill(dtProductsTemp);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        return dtProductsTemp.DefaultView;&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private void FillPagesDropDownList(int iTotalPages)&lt;br /&gt;    {&lt;br /&gt;        ddlpageNumbers.Items.Clear();&lt;br /&gt;        for (int i = 1; i &lt;= iTotalPages; i++)&lt;br /&gt;        {&lt;br /&gt;            ddlpageNumbers.Items.Add(new ListItem(i.ToString(), i.ToString()));&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    #endregion&lt;br /&gt;&lt;br /&gt;    #region "Properties"&lt;br /&gt;&lt;br /&gt;    private int ThisPageNumber&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            object obj = ViewState["ThisPageNumber"];&lt;br /&gt;            return (obj == null) ? 0 : (int)obj;&lt;br /&gt;        }&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            this.ViewState["ThisPageNumber"] = value;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    #endregion&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Extra Namespace used&lt;br /&gt;&lt;pre name="code" class="csharp"&gt;&lt;br /&gt;using System.Data.SqlClient;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;P.S: DataBase used is Northwind&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-141350710968131361?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/141350710968131361/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2009/07/heres-sample-on-how-to-implement-paging.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/141350710968131361'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/141350710968131361'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2009/07/heres-sample-on-how-to-implement-paging.html' title='Paging in Repeater'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-2339422527752687460</id><published>2009-05-15T23:34:00.018+05:30</published><updated>2009-10-05T16:58:42.296+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='subtotal gridview'/><title type='text'>SubTotals in GridView</title><content type='html'>To display Sub Totals in a GridView is a situation that arise frequently.&lt;br /&gt;&lt;br /&gt;Here's a sample on how to do it using GridView.&lt;br /&gt;&lt;br /&gt;First we need a table TBL_Patients. Here's the structure&lt;br /&gt;&lt;br /&gt;&lt;img style="cursor:pointer; cursor:hand;width: 338px; height 142px;" src="http://sites.google.com/site/fun2code/Home/tablestructure.JPG" border="0" alt="" /&gt;&lt;br /&gt;&lt;br /&gt;Now lets populate some sample values to it.&lt;br /&gt;&lt;br /&gt;&lt;img style="cursor:pointer; cursor:hand;width: 502px; height: 212px;" src="http://sites.google.com/site/fun2code/Home/tablevalues.JPG" border="0" alt="" /&gt;&lt;br /&gt;&lt;br /&gt;The ASPX&lt;br /&gt;&lt;pre name="code" class="xhtml"&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;asp:GridView ID=&amp;quot;gvwPatientBill&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;                    AutoGenerateColumns=&amp;quot;false&amp;quot;&lt;br /&gt;                    DataKeyNames=&amp;quot;BillID&amp;quot;&lt;br /&gt;                    GridLines=&amp;quot;Both&amp;quot;&lt;br /&gt;                    OnRowDataBound=&amp;quot;gvwPatientBill_RowDataBound&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;Columns&amp;gt;&lt;br /&gt;            &amp;lt;asp:TemplateField HeaderText=&amp;quot;Bill ID&amp;quot;&amp;gt;&lt;br /&gt;                &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;                    &amp;lt;asp:Label ID=&amp;quot;lblBillID&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;                            Text='&amp;lt;%# Eval(&amp;quot;BillID&amp;quot;) %&amp;gt;'&amp;gt;&lt;br /&gt;                    &amp;lt;/asp:Label&amp;gt;&lt;br /&gt;                &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;            &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;            &amp;lt;asp:TemplateField HeaderText=&amp;quot;Patient ID&amp;quot;&amp;gt;&lt;br /&gt;                &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;                    &amp;lt;asp:Label ID=&amp;quot;lblPatientID&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;                            Text='&amp;lt;%# Eval(&amp;quot;PatientID&amp;quot;) %&amp;gt;'&amp;gt;&lt;br /&gt;                    &amp;lt;/asp:Label&amp;gt;&lt;br /&gt;                &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;            &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;            &amp;lt;asp:TemplateField HeaderText=&amp;quot;Patient Name&amp;quot;&amp;gt;&lt;br /&gt;                &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;                    &amp;lt;asp:Label ID=&amp;quot;lblPatientName&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;                            Text='&amp;lt;%# Eval(&amp;quot;PatientName&amp;quot;) %&amp;gt;'&amp;gt;&lt;br /&gt;                    &amp;lt;/asp:Label&amp;gt;&lt;br /&gt;                &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;            &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;            &amp;lt;asp:TemplateField HeaderText=&amp;quot;Patient Ward&amp;quot;&amp;gt;&lt;br /&gt;                &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;                    &amp;lt;asp:Label ID=&amp;quot;lblPatientWard&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;                            Text='&amp;lt;%# Eval(&amp;quot;PatientWard&amp;quot;) %&amp;gt;'&amp;gt;&lt;br /&gt;                    &amp;lt;/asp:Label&amp;gt;&lt;br /&gt;                &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;            &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;            &amp;lt;asp:TemplateField HeaderText=&amp;quot;Bill Amount&amp;quot;&amp;gt;&lt;br /&gt;                &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;                    &amp;lt;asp:Label ID=&amp;quot;lblBillAmount&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;                            Text='&amp;lt;%# Eval(&amp;quot;BillAmount&amp;quot;) %&amp;gt;'&amp;gt;&lt;br /&gt;                    &amp;lt;/asp:Label&amp;gt;&lt;br /&gt;                &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;            &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;        &amp;lt;/Columns&amp;gt;&lt;br /&gt;        &amp;lt;HeaderStyle BackColor=&amp;quot;Black&amp;quot; ForeColor=&amp;quot;White&amp;quot; /&amp;gt;&lt;br /&gt;    &amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The ASPX.CS&lt;br /&gt;&lt;pre name="code" class="csharp"&gt;&lt;br /&gt;int iPatientIDCount = 0;&lt;br /&gt;int iRowsCount = 0;&lt;br /&gt;int iAddBills = 0;&lt;br /&gt;string sPatientID = "";&lt;br /&gt;&lt;br /&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    if (!IsPostBack)&lt;br /&gt;    {&lt;br /&gt;        BindGridView();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private void BindGridView()&lt;br /&gt;{&lt;br /&gt;    DataTable dtPatientBills = new DataTable();&lt;br /&gt;    string strSelectCommand = "SELECT * FROM TBL_PatientBills ORDER BY PatientID";&lt;br /&gt;    using (SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString))&lt;br /&gt;    {&lt;br /&gt;        using (SqlDataAdapter adapPatientBills = new SqlDataAdapter(strSelectCommand, sqlConn))&lt;br /&gt;        {&lt;br /&gt;            adapPatientBills.Fill(dtPatientBills);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    iRowsCount = dtPatientBills.Rows.Count - 1;&lt;br /&gt;    gvwPatientBill.DataSource = dtPatientBills;&lt;br /&gt;    gvwPatientBill.DataBind();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void gvwPatientBill_RowDataBound(object sender, GridViewRowEventArgs e)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;    if (e.Row.RowType == DataControlRowType.DataRow)&lt;br /&gt;    {&lt;br /&gt;        string sName = "";&lt;br /&gt;        if (e.Row.RowIndex == 0)&lt;br /&gt;        {&lt;br /&gt;            sPatientID = ((Label)e.Row.FindControl("lblPatientID")).Text;&lt;br /&gt;            iAddBills = Convert.ToInt32(((Label)e.Row.FindControl("lblBillAmount")).Text);&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            sName = ((Label)gvwPatientBill.Rows[e.Row.RowIndex - 1].FindControl("lblPatientName")).Text;&lt;br /&gt;            iPatientIDCount = iPatientIDCount + 1;&lt;br /&gt;            if (sPatientID == ((Label)e.Row.FindControl("lblPatientID")).Text)&lt;br /&gt;            {&lt;br /&gt;                iAddBills += Convert.ToInt32(((Label)e.Row.FindControl("lblBillAmount")).Text);&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                sPatientID = ((Label)e.Row.FindControl("lblPatientID")).Text;&lt;br /&gt;                Table tblTemp = (Table)this.gvwPatientBill.Controls[0];&lt;br /&gt;                int intIndex = tblTemp.Rows.GetRowIndex(e.Row);&lt;br /&gt;                GridViewRow gvrSubTotal = CreateGridViewRow(&lt;br /&gt;                        intIndex,&lt;br /&gt;                        "#8FD8D8",&lt;br /&gt;                        gvwPatientBill.Columns.Count,&lt;br /&gt;                        "Total for " + sName + " in " + iPatientIDCount + " Entries: " + iAddBills,&lt;br /&gt;                        20);&lt;br /&gt;                tblTemp.Controls.AddAt(intIndex, gvrSubTotal);&lt;br /&gt;                iPatientIDCount = 0;&lt;br /&gt;                iAddBills = Convert.ToInt32(((Label)e.Row.FindControl("lblBillAmount")).Text);&lt;br /&gt;            }&lt;br /&gt;            if (iRowsCount == e.Row.RowIndex)&lt;br /&gt;            {&lt;br /&gt;                sName = ((Label)e.Row.FindControl("lblPatientName")).Text;&lt;br /&gt;                Table tblTemp = (Table)this.gvwPatientBill.Controls[0];&lt;br /&gt;                int intIndex = tblTemp.Rows.GetRowIndex(e.Row) + 1;&lt;br /&gt;&lt;br /&gt;                GridViewRow gvrLast = CreateGridViewRow(&lt;br /&gt;                        intIndex,&lt;br /&gt;                        "#8FD8D8",&lt;br /&gt;                        gvwPatientBill.Columns.Count,&lt;br /&gt;                        "Total for " + sName + " in " + iPatientIDCount + " Entries: " + iAddBills,&lt;br /&gt;                        20);&lt;br /&gt;                tblTemp.Controls.AddAt(intIndex, gvrLast);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private GridViewRow CreateGridViewRow(int iCurrentIndex, string sTableBackColor,int iTableColumnSpan, string sTableText, int iTableHeight)&lt;br /&gt;{&lt;br /&gt;    GridViewRow gvrTemp = new GridViewRow(iCurrentIndex, iCurrentIndex, DataControlRowType.Separator, DataControlRowState.Normal);&lt;br /&gt;    TableCell cellTemp = new TableCell();&lt;br /&gt;    cellTemp.BackColor = System.Drawing.ColorTranslator.FromHtml("#8FD8D8");&lt;br /&gt;    cellTemp.Font.Bold = true;&lt;br /&gt;    cellTemp.ColumnSpan = iTableColumnSpan;&lt;br /&gt;    cellTemp.HorizontalAlign = HorizontalAlign.Left;&lt;br /&gt;    cellTemp.Text = sTableText;&lt;br /&gt;    cellTemp.Height = Unit.Pixel(iTableHeight);&lt;br /&gt;    gvrTemp.Cells.Add(cellTemp);&lt;br /&gt;    return gvrTemp;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And the final result looks like this.&lt;br /&gt;&lt;img style="cursor:pointer; cursor:hand;width: 387px; height: 295px;" src="http://sites.google.com/site/fun2code/Home/billdetails.jpg" border="0" alt="" /&gt;&lt;br /&gt;&lt;br /&gt;NB: Its a no-no if you wanna implement Paging and Sorting here. For that, we have to use the wonderful third party &lt;br /&gt;GridView controls like Teleriks RadGrid and all&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-2339422527752687460?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/2339422527752687460/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2009/05/subtotal-in-gridview.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/2339422527752687460'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/2339422527752687460'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2009/05/subtotal-in-gridview.html' title='SubTotals in GridView'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-2927929036525476636</id><published>2009-03-25T13:25:00.002+05:30</published><updated>2009-10-05T17:02:00.431+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='paging and filtering gridview'/><title type='text'>Paging a Filtered GridView</title><content type='html'>&lt;blockquote&gt;&lt;span style="font-weight:bold;"&gt;In many forums there are people struggling with filtering and paging in gridview.&lt;br /&gt;When separated, both filtering and paging works smoothly.&lt;br /&gt;But when trying to change the page index of a filtered result set, all hell will break loose.&lt;br /&gt;Mostly a new page with the unfiltered result set comes into play.&lt;/span&gt; &lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Here's a sample on how to do it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The ASPX&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="xhtml"&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;table&amp;gt;&lt;br /&gt;    &amp;lt;tr&amp;gt;&lt;br /&gt;        &amp;lt;td&amp;gt;&lt;br /&gt;            Search By Product Name:&lt;br /&gt;        &amp;lt;/td&amp;gt;&lt;br /&gt;        &amp;lt;td&amp;gt;&lt;br /&gt;            &amp;lt;asp:TextBox ID=&amp;quot;txtProductName&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;br /&gt;        &amp;lt;/td&amp;gt;&lt;br /&gt;        &amp;lt;td&amp;gt;&lt;br /&gt;            &amp;lt;asp:Button ID=&amp;quot;btnBindGridView&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;                        Text=&amp;quot;Populate Grid&amp;quot; onclick=&amp;quot;btnBindGridView_Click&amp;quot; /&amp;gt;&lt;br /&gt;        &amp;lt;/td&amp;gt;&lt;br /&gt;    &amp;lt;/tr&amp;gt;&lt;br /&gt;    &amp;lt;tr&amp;gt;&lt;br /&gt;        &amp;lt;td colspan=&amp;quot;3&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;asp:GridView ID=&amp;quot;gvwProducts&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;                            AllowPaging=&amp;quot;true&amp;quot;&lt;br /&gt;                            AutoGenerateColumns=&amp;quot;false&amp;quot;&lt;br /&gt;                            PageSize=&amp;quot;3&amp;quot; &lt;br /&gt;                            OnPageIndexChanging=&amp;quot;gvwProducts_PageIndexChanging&amp;quot;&amp;gt;&lt;br /&gt;                &amp;lt;Columns&amp;gt;&lt;br /&gt;                    &amp;lt;asp:BoundField DataField=&amp;quot;ProductName&amp;quot; HeaderText=&amp;quot;Product Name&amp;quot;/&amp;gt;&lt;br /&gt;                    &amp;lt;asp:BoundField DataField=&amp;quot;QuantityPerUnit&amp;quot; HeaderText=&amp;quot;Quantity&amp;quot;/&amp;gt;&lt;br /&gt;                    &amp;lt;asp:BoundField DataField=&amp;quot;UnitPrice&amp;quot; HeaderText=&amp;quot;Price&amp;quot;/&amp;gt;&lt;br /&gt;                &amp;lt;/Columns&amp;gt;&lt;br /&gt;            &amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;        &amp;lt;/td&amp;gt;&lt;br /&gt;    &amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The ASPX.CS&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="csharp"&gt;&lt;br /&gt;&lt;br /&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    if (!IsPostBack)&lt;br /&gt;    {&lt;br /&gt;        BindGridView();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void btnBindGridView_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    BindGridView();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void gvwProducts_PageIndexChanging(object sender, GridViewPageEventArgs e)&lt;br /&gt;{&lt;br /&gt;    gvwProducts.PageIndex = e.NewPageIndex;&lt;br /&gt;    BindGridView();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private void BindGridView()&lt;br /&gt;{&lt;br /&gt;    DataTable dtProducts = new DataTable();&lt;br /&gt;    string strSelectCommand = "SELECT * FROM Products" &lt;br /&gt;            + ((txtProductName.Text.Trim() == "") ? "" : (" WHERE ProductName LIKE '" + txtProductName.Text.Trim() + "%'"));&lt;br /&gt;    using (SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString))&lt;br /&gt;    {&lt;br /&gt;        using (SqlDataAdapter adapProducts = new SqlDataAdapter(strSelectCommand, sqlConn))&lt;br /&gt;        {&lt;br /&gt;            adapProducts.Fill(dtProducts);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    gvwProducts.DataSource = dtProducts;&lt;br /&gt;    gvwProducts.DataBind();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;DataBase used --&gt; Northwind&lt;br /&gt;Extra Namespace used --&gt;System.Data.SqlClient;&lt;br /&gt;&lt;br /&gt;Hope this helps!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-2927929036525476636?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/2927929036525476636/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2009/03/paging-filtered-gridview.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/2927929036525476636'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/2927929036525476636'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2009/03/paging-filtered-gridview.html' title='Paging a Filtered GridView'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-3302829138723954690</id><published>2009-03-16T11:06:00.007+05:30</published><updated>2009-10-05T17:02:17.029+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='gridview filtering datalist filter alphabet'/><title type='text'>Filtered GridView using DataList</title><content type='html'>Many times the requirement comes like this.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;need to show  the first letter of products as a link outside grid and when the user clicks on it the grid will be showing the result with that particular product only.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Can be easily done using GridView and DataList.&lt;br /&gt;Database used is Northwind.&lt;br /&gt;&lt;br /&gt;The ASPX&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="xhtml"&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;asp:DataList ID="dlstProducts" runat="server"&lt;br /&gt;               RepeatDirection="Horizontal"&amp;gt;&lt;br /&gt;   &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;       &amp;lt;asp:LinkButton ID="lnkFirstLetters" runat="server"&lt;br /&gt;                       Text='&amp;lt;%# Bind("ProductNameFirstLetter") %&amp;gt;'&lt;br /&gt;           onclick="lnkFirstLetters_Click"&amp;gt;&lt;br /&gt;       &amp;lt;/asp:LinkButton&amp;gt;&lt;br /&gt;   &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;/asp:DataList&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;asp:GridView ID="gvwProducts" runat="server"&lt;br /&gt;               AutoGenerateColumns="false"&lt;br /&gt;               DataKeyNames="ProductID"&amp;gt;&lt;br /&gt;   &amp;lt;Columns&amp;gt;&lt;br /&gt;       &amp;lt;asp:TemplateField HeaderText="Product Name"&amp;gt;&lt;br /&gt;           &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;               &amp;lt;asp:Label ID="lblProductName" runat="server" Text='&amp;lt;%# Bind("ProductName") %&amp;gt;'&amp;gt;&lt;br /&gt;               &amp;lt;/asp:Label&amp;gt;&lt;br /&gt;           &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;       &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;       &amp;lt;asp:TemplateField HeaderText="Quantity Per Unit"&amp;gt;&lt;br /&gt;           &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;               &amp;lt;asp:Label ID="lblQuantityPerUnit" runat="server" Text='&amp;lt;%# Bind("QuantityPerUnit") %&amp;gt;'&amp;gt;&lt;br /&gt;               &amp;lt;/asp:Label&amp;gt;&lt;br /&gt;           &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;       &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;   &amp;lt;/Columns&amp;gt;&lt;br /&gt;&amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The ASPX.CS&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="csharp"&gt;&lt;br /&gt;&lt;br /&gt;public partial class GridView_GridViewDataListFirstAlphabet : System.Web.UI.Page&lt;br /&gt;{&lt;br /&gt;   DataTable dtProducts = new DataTable();&lt;br /&gt;&lt;br /&gt;   protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;   {&lt;br /&gt;       if (!IsPostBack)&lt;br /&gt;       {&lt;br /&gt;           InitialBindOfControls();&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   protected void lnkFirstLetters_Click(object sender, EventArgs e)&lt;br /&gt;   {&lt;br /&gt;       BindGridView(((LinkButton)sender).Text.Trim());&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   private void InitialBindOfControls()&lt;br /&gt;   {&lt;br /&gt;       BindGridView("Initial");&lt;br /&gt;       BindDataList();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   private void BindGridView(string strChar)&lt;br /&gt;   {&lt;br /&gt;       string strQuery = "SELECT ProductID, ProductName, QuantityPerUnit FROM Products "&lt;br /&gt;                   + ((strChar == "Initial") ? "" : "WHERE ProductName LIKE'" + strChar + "%'")&lt;br /&gt;                   + "ORDER BY ProductName";&lt;br /&gt;       using (SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ToString()))&lt;br /&gt;       {&lt;br /&gt;           using (SqlDataAdapter adapProducts = new SqlDataAdapter(strQuery, sqlConn))&lt;br /&gt;           {&lt;br /&gt;               adapProducts.Fill(dtProducts);&lt;br /&gt;               gvwProducts.DataSource = dtProducts;&lt;br /&gt;               gvwProducts.DataBind();&lt;br /&gt;           }&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   private void BindDataList()&lt;br /&gt;   {&lt;br /&gt;       if (gvwProducts.Rows.Count != 0)&lt;br /&gt;       {&lt;br /&gt;           DataTable dtTemp = new DataTable();&lt;br /&gt;           dtTemp.Columns.Add("ProductNameFirstLetter");&lt;br /&gt;           dtTemp.Rows.Add(((Label)gvwProducts.Rows[0].FindControl("lblProductName")).Text.Substring(0, 1));&lt;br /&gt;           foreach (GridViewRow gvrProducts in gvwProducts.Rows)&lt;br /&gt;           {&lt;br /&gt;               if (dtTemp.Rows[dtTemp.Rows.Count - 1][0].ToString() != ((Label)gvrProducts.FindControl("lblProductName")).Text.Substring(0, 1))&lt;br /&gt;               {&lt;br /&gt;                   dtTemp.Rows.Add(((Label)gvrProducts.FindControl("lblProductName")).Text.Substring(0, 1));&lt;br /&gt;               }&lt;br /&gt;           }&lt;br /&gt;           dlstProducts.DataSource = dtTemp;&lt;br /&gt;           dlstProducts.DataBind();&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Extra Namespace used&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="brush: csharp"&gt;&lt;br /&gt;using System.Data.SqlClient;&lt;br/&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-3302829138723954690?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/3302829138723954690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2009/03/filtered-gridview-using-datalist.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/3302829138723954690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/3302829138723954690'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2009/03/filtered-gridview-using-datalist.html' title='Filtered GridView using DataList'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-6148577956120495064</id><published>2009-02-02T09:56:00.012+05:30</published><updated>2010-12-07T19:03:12.535+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='gridview checkbox paging maintaining persisting state'/><title type='text'>Maintaining State of CheckBox while Paging in GridView</title><content type='html'>The Logic&lt;br /&gt;&lt;blockquote&gt;We are storing the primary keys of the checkboxes that are checked into a List&lt;T&gt; where T = data type of the primary key. This is done at PageIndexChanging before we change the page index and re-bind the GridView. And at RowDataBound we are checking whether the DataKeyName(primary key) of each row is in the List. If present , we mark the CheckBox as checked.&lt;/blockquote&gt;Heres the sample code.&lt;br /&gt;&lt;br /&gt;The ASPX&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:xhtml"&gt;&amp;lt;asp:LinkButton ID=&amp;quot;btnSelectAllPage&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;            CommandName=&amp;quot;SelectAllPage&amp;quot; &lt;br /&gt;            Text=&amp;quot;Select All Pages&amp;quot;&lt;br /&gt;            OnCommand=&amp;quot;SelectDeselectAllPages&amp;quot; /&amp;gt;|&lt;br /&gt;&amp;lt;asp:LinkButton ID=&amp;quot;btnDeselectAllPage&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;            CommandName=&amp;quot;DeselectAllPage&amp;quot; &lt;br /&gt;            Text=&amp;quot;Deselect All Pages&amp;quot;&lt;br /&gt;            OnCommand=&amp;quot;SelectDeselectAllPages&amp;quot; /&amp;gt;|&lt;br /&gt;&amp;lt;asp:LinkButton ID=&amp;quot;btnSelectAll&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;            CommandName=&amp;quot;SelectAll&amp;quot; &lt;br /&gt;            Text=&amp;quot;Select Page&amp;quot;&lt;br /&gt;            OnCommand=&amp;quot;SelectDeselect&amp;quot; /&amp;gt;|&lt;br /&gt;&amp;lt;asp:LinkButton ID=&amp;quot;btnDeselectAll&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;            CommandName=&amp;quot;DeselectAll&amp;quot; &lt;br /&gt;            Text=&amp;quot;Deselect Page&amp;quot;&lt;br /&gt;            OnCommand=&amp;quot;SelectDeselect&amp;quot; /&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;asp:GridView ID=&amp;quot;gvProducts&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;            AllowPaging=&amp;quot;True&amp;quot; &lt;br /&gt;            AutoGenerateColumns=&amp;quot;False&amp;quot;&lt;br /&gt;            DataKeyNames=&amp;quot;ProductID&amp;quot;&lt;br /&gt;            OnPageIndexChanging=&amp;quot;gvProducts_PageIndexChanging&amp;quot; &lt;br /&gt;            OnRowDataBound=&amp;quot;gvProducts_RowDataBound&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;Columns&amp;gt;&lt;br /&gt;        &amp;lt;asp:TemplateField HeaderText=&amp;quot;Select&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;                &amp;lt;asp:CheckBox ID=&amp;quot;chkSelect&amp;quot; runat=&amp;quot;server&amp;quot; /&amp;gt;&lt;br /&gt;            &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;        &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;    &amp;lt;asp:BoundField DataField=&amp;quot;ProductID&amp;quot; HeaderText=&amp;quot;ProductID&amp;quot; InsertVisible=&amp;quot;False&amp;quot;&lt;br /&gt;    ReadOnly=&amp;quot;True&amp;quot; SortExpression=&amp;quot;ProductID&amp;quot; /&amp;gt;&lt;br /&gt;    &amp;lt;asp:BoundField DataField=&amp;quot;ProductName&amp;quot; HeaderText=&amp;quot;ProductName&amp;quot; SortExpression=&amp;quot;ProductName&amp;quot; /&amp;gt;&lt;br /&gt;    &amp;lt;/Columns&amp;gt;&lt;br /&gt;&amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;&amp;lt;asp:SqlDataSource ID=&amp;quot;sdsProducts&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;                ConnectionString=&amp;#39;&amp;lt;%$ ConnectionStrings:NorthwindConnectionString %&amp;gt;&amp;#39;&lt;br /&gt;                SelectCommand=&amp;quot;SELECT * FROM Products&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/asp:SqlDataSource&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The ASPX.CS&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:csharp"&gt;private List&amp;lt;int&amp;gt; ProductIDs&lt;br /&gt;{&lt;br /&gt;    get&lt;br /&gt;    {&lt;br /&gt;        if (this.ViewState[&amp;quot;ProductIDs&amp;quot;] == null)&lt;br /&gt;        {&lt;br /&gt;            this.ViewState[&amp;quot;ProductIDs&amp;quot;] = new List&amp;lt;int&amp;gt;();&lt;br /&gt;        }&lt;br /&gt;        return this.ViewState[&amp;quot;ProductIDs&amp;quot;] as List&amp;lt;int&amp;gt;;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void SelectDeselect(object sender, CommandEventArgs e)&lt;br /&gt;{&lt;br /&gt;    foreach (GridViewRow gvr in gvProducts.Rows)&lt;br /&gt;    {&lt;br /&gt;        CheckBox chkSelect = gvr.FindControl(&amp;quot;chkSelect&amp;quot;) as CheckBox;&lt;br /&gt;        if (chkSelect != null)&lt;br /&gt;        {&lt;br /&gt;            chkSelect.Checked = e.CommandName.Equals(&amp;quot;SelectAll&amp;quot;);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void SelectDeselectAllPages(object sender, CommandEventArgs e)&lt;br /&gt;{&lt;br /&gt;    DataSourceSelectArguments dssa = new DataSourceSelectArguments();&lt;br /&gt;    dssa.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);&lt;br /&gt;    dssa.RetrieveTotalRowCount = true;&lt;br /&gt;    DataView dv = (DataView)sdsProducts.Select(dssa);&lt;br /&gt;    foreach (DataRow dr in dv.Table.Rows)&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;        int productID = Convert.ToInt32(dr.ItemArray[0]);//ItemArray[0] cos ProductID is in the first column&lt;br /&gt;        if (e.CommandName.Equals(&amp;quot;SelectAllPage&amp;quot;) &amp;amp;&amp;amp; !this.ProductIDs.Contains(productID))&lt;br /&gt;        {&lt;br /&gt;            this.ProductIDs.Add(productID);&lt;br /&gt;        }&lt;br /&gt;        if (e.CommandName.Equals(&amp;quot;DeselectAllPage&amp;quot;) &amp;amp;&amp;amp; this.ProductIDs.Contains(productID))&lt;br /&gt;        {&lt;br /&gt;            this.ProductIDs.Remove(productID);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    foreach (GridViewRow gvr in gvProducts.Rows)&lt;br /&gt;    {&lt;br /&gt;        CheckBox chkSelect = gvr.FindControl(&amp;quot;chkSelect&amp;quot;) as CheckBox;&lt;br /&gt;        if (chkSelect != null)&lt;br /&gt;        {&lt;br /&gt;            chkSelect.Checked = e.CommandName.Equals(&amp;quot;SelectAllPage&amp;quot;);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void gvProducts_PageIndexChanging(object sender, GridViewPageEventArgs e)&lt;br /&gt;{&lt;br /&gt;    foreach (GridViewRow gvr in gvProducts.Rows)&lt;br /&gt;    {&lt;br /&gt;        CheckBox chkSelect = gvr.FindControl(&amp;quot;chkSelect&amp;quot;) as CheckBox;&lt;br /&gt;        if (chkSelect != null)&lt;br /&gt;        {&lt;br /&gt;            int productID = Convert.ToInt32(gvProducts.DataKeys[gvr.RowIndex][&amp;quot;ProductID&amp;quot;]);&lt;br /&gt;            if (chkSelect.Checked &amp;amp;&amp;amp; !this.ProductIDs.Contains(productID))&lt;br /&gt;            {&lt;br /&gt;                this.ProductIDs.Add(productID);&lt;br /&gt;            }&lt;br /&gt;            else if (!chkSelect.Checked &amp;amp;&amp;amp; this.ProductIDs.Contains(productID))&lt;br /&gt;            {&lt;br /&gt;                this.ProductIDs.Remove(productID);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void gvProducts_RowDataBound(object sender, GridViewRowEventArgs e)&lt;br /&gt;{&lt;br /&gt;    GridViewRow gvr = e.Row;&lt;br /&gt;    if (gvr.RowType == DataControlRowType.DataRow)&lt;br /&gt;    {&lt;br /&gt;        CheckBox chkSelect = gvr.FindControl(&amp;quot;chkSelect&amp;quot;) as CheckBox;&lt;br /&gt;        if (chkSelect != null)&lt;br /&gt;        {&lt;br /&gt;            int productID = Convert.ToInt32(gvProducts.DataKeys[gvr.RowIndex][&amp;quot;ProductID&amp;quot;]);&lt;br /&gt;            chkSelect.Checked = this.ProductIDs.Contains(productID);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As an extra enhancement, we are also giving provision for selecting, deselecting both page and the whole rows in every page also here.&lt;br /&gt;&lt;br /&gt;P.S: We are using Northwind Sample DataBase by Microsoft, so if you dont have it download it.&lt;br /&gt;&lt;br /&gt;Courtesy: A &lt;a href="http://forums.asp.net/p/1370809/2866640.aspx#2866838"&gt;wonderful post&lt;/a&gt; by Ed Bruck at forums.asp.net&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-6148577956120495064?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/6148577956120495064/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2009/02/maintaining-state-of-checkbox-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/6148577956120495064'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/6148577956120495064'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2009/02/maintaining-state-of-checkbox-in.html' title='Maintaining State of CheckBox while Paging in GridView'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-8490612285228115134</id><published>2009-02-01T13:33:00.007+05:30</published><updated>2011-03-15T22:34:57.448+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='inser custom row gridview'/><title type='text'>Insert Custom Advertisement Row in GridView</title><content type='html'>Inserting advertisements between,say every tenth row populated by a gridview&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The ASPX&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:xml"&gt;&amp;lt;asp:GridView ID=&amp;quot;GridView1&amp;quot; runat=&amp;quot;server&amp;quot;  &lt;br /&gt;AutoGenerateColumns=&amp;quot;False&amp;quot;  &lt;br /&gt;Height=&amp;quot;171px&amp;quot; &lt;br /&gt;DataSourceID=&amp;quot;sdsProducts&amp;quot;&lt;br /&gt;Width=&amp;quot;189px&amp;quot; &lt;br /&gt;OnRowDataBound=&amp;quot;GridView1_RowDataBound&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;Columns&amp;gt;&lt;br /&gt;&amp;lt;asp:BoundField DataField=&amp;quot;ProductID&amp;quot; HeaderText=&amp;quot;ProductID&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;asp:BoundField DataField=&amp;quot;ProductName&amp;quot; HeaderText=&amp;quot;ProductName&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/Columns&amp;gt;&lt;br /&gt;&amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;&amp;lt;asp:SqlDataSource ID=&amp;quot;sdsProducts&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;ConnectionString='&amp;lt;%$ ConnectionStrings:NorthwindConnectionString %&amp;gt;'&lt;br /&gt;SelectCommand=&amp;quot;SELECT * FROM Products&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/asp:SqlDataSource&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The ASPX.CS&lt;br /&gt;&lt;pre class="brush:csharp"&gt;protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)&lt;br /&gt;{&lt;br /&gt;if (e.Row.DataItem != null)&lt;br /&gt;{&lt;br /&gt;int intCurrentId = e.Row.RowIndex;&lt;br /&gt;if ((intCurrentId + 1) % 10 == 0)&lt;br /&gt;{&lt;br /&gt;// Add a row before this record&lt;br /&gt;Table tblGrid = (Table)this.GridView1.Controls[0];&lt;br /&gt;// Get the rowindex of the current row&lt;br /&gt;int intIndex = tblGrid.Rows.GetRowIndex(e.Row);&lt;br /&gt;// Create a new row to hold our subheading&lt;br /&gt;GridViewRow gvrSubHeading = new GridViewRow(intIndex, intIndex, DataControlRowType.Separator, DataControlRowState.Normal);&lt;br /&gt;// Create a table cell for the row&lt;br /&gt;TableCell cellHeader = new TableCell();&lt;br /&gt;// Set the colspan of the cell to the width of the table&lt;br /&gt;cellHeader.ColumnSpan = this.GridView1.Columns.Count;&lt;br /&gt;// Set the text&lt;br /&gt;cellHeader.Text = "Your Advertisement goes here";&lt;br /&gt;// Add the cell to the row&lt;br /&gt;gvrSubHeading.Cells.Add(cellHeader);&lt;br /&gt;// Add the row to the table&lt;br /&gt;tblGrid.Controls.AddAt(intIndex + 1, gvrSubHeading);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Thats all.&lt;br /&gt;&lt;br /&gt;P.S: The DataBase used is Northwind&lt;br /&gt;&lt;br /&gt;Courtesy : Samu Zhang - MSFT of http://forums.asp.net&lt;br /&gt;The original VB version posted by Samu Zhang can be found &lt;a href="http://forums.asp.net/t/1372107.aspx#2878302"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-8490612285228115134?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/8490612285228115134/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2009/02/insert-custom-advertisement-row-in_01.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/8490612285228115134'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/8490612285228115134'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2009/02/insert-custom-advertisement-row-in_01.html' title='Insert Custom Advertisement Row in GridView'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-6029466623843227659</id><published>2008-10-22T11:36:00.006+05:30</published><updated>2009-10-05T17:03:19.667+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='remove div input node javascript jquery'/><title type='text'>Remove a HTML Element using Javascript</title><content type='html'>Suppose the ID of the element is "objID"&lt;br /&gt;&lt;br /&gt;The JavaScript method.(We are writing a custom function)&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="jscript"&gt;&lt;br /&gt;&lt;br /&gt;function removeElement(objID) {&lt;br /&gt;    var node = document.getElementById(objID);&lt;br /&gt;    node.parentNode.removeChild(node);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The JQuery method.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="jscript"&gt;&lt;br /&gt;&lt;br /&gt;$("#objID").remove();&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Its all about &lt;span style="font-weight:bold;"&gt;Keeping it Simple&lt;/span&gt;.&lt;br /&gt;What do you say? :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-6029466623843227659?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/6029466623843227659/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2008/10/remove-html-element-using-javascript.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/6029466623843227659'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/6029466623843227659'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2008/10/remove-html-element-using-javascript.html' title='Remove a HTML Element using Javascript'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-3198551773829926007</id><published>2008-10-16T14:03:00.006+05:30</published><updated>2009-10-05T17:08:48.962+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='copy datatable row'/><title type='text'>Copy DataRows from one DataTable to Another</title><content type='html'>"This row already belongs to another table" - Annoying, to say the least!&lt;br /&gt;&lt;br /&gt;The workaround, simple but elusive.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="csharp"&gt;&lt;br /&gt;&lt;br /&gt;public DataTable CopyDataTable(DataTable dtSource, int iRowsNeeded)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;    if (dtSource.Rows.Count &gt; iRowsNeeded)&lt;br /&gt;    {&lt;br /&gt;        // cloned to get the structure of source&lt;br /&gt;        DataTable dtDestination = dtSource.Clone();&lt;br /&gt;        for (int i = 0; i &lt; iRowsNeeded; i++)&lt;br /&gt;        {&lt;br /&gt;            dtDestination.ImportRow(dtSource.Rows[i]);&lt;br /&gt;        }&lt;br /&gt;        return dtDestination;&lt;br /&gt;    }&lt;br /&gt;    else&lt;br /&gt;        return dtSource;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Happy Coding!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-3198551773829926007?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/3198551773829926007/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2008/10/copy-datarows-from-one-datatable-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/3198551773829926007'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/3198551773829926007'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2008/10/copy-datarows-from-one-datatable-to.html' title='Copy DataRows from one DataTable to Another'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-5924451625750375478</id><published>2008-09-29T11:40:00.007+05:30</published><updated>2009-03-25T11:01:16.803+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='jquery visual studio'/><category scheme='http://www.blogger.com/atom/ns#' term='jquery'/><category scheme='http://www.blogger.com/atom/ns#' term='jquery microsoft'/><title type='text'>JQuery Time</title><content type='html'>&lt;a href="http://www.jquery.com/"&gt;jQuery&lt;/a&gt; is a lightweight open source JavaScript library developed&lt;br /&gt;under the management of &lt;a href="http://ejohn.org/"title="JavaScript Evangelist for the Mozilla Corporation"&gt;John Resig&lt;/a&gt; .&lt;br /&gt;For those ASP.NET Developers who dont know &lt;a href="http://www.jquery.com/"&gt;jQuery&lt;/a&gt;, its seriously &lt;span style="font-weight:bold;"&gt;DO or DIE&lt;/span&gt;&lt;br /&gt;For those who think &lt;a href="http://www.jquery.com/"&gt;jQuery &lt;/a&gt;is totally needless, its time to rethink.&lt;br /&gt;&lt;br /&gt;Because &lt;a href="http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx" title="Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework."&gt;&lt;br /&gt;Scott Guthrie&lt;/a&gt; (You ought to know the him!) yesterday announced that &lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Microsoft Microsoft will be shipping jQuery with Visual Studio going forward....&lt;br /&gt;.................................................................................&lt;br /&gt;Going forward we'll use jQuery as one of the libraries used to implement higher-level &lt;br /&gt;controls in the ASP.NET AJAX Control Toolkit, as well as to implement new &lt;br /&gt;Ajax server-side helper methods for ASP.NET MVC.  &lt;br /&gt;New features we add to ASP.NET AJAX (like the new client template support) &lt;br /&gt;will be designed to integrate nicely with jQuery as well.&lt;/blockquote&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Heres the corresponding entry in the &lt;a href="http://jquery.com/blog/2008/09/28/jquery-microsoft-nokia/"&gt;jQuery Team Blog&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;So its time to start taking jQuery a lot more seriously. [:)]&lt;br /&gt;&lt;br /&gt;For starters:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;1. The book "jQuery in Action".&lt;br /&gt;       Order from IndiaPlaza &lt;a href="http://www.indiaplaza.in/books/all/9788177228878/all/jquery-in-action.htm"&gt;(Click Here)&lt;/a&gt;&lt;br /&gt;2. A superb introductory article by Rick Strahl. &lt;a href="http://www.west-wind.com/presentations/jQuery/default.aspx"&gt;(Click Here)&lt;/a&gt;&lt;br /&gt;3. Another good article by Scott HanselMan.&lt;a href="http://www.hanselman.com/blog/jQuerytoshipwithASPNETMVCandVisualStudio.aspx"&gt;(Click Here)&lt;/a&gt;&lt;br /&gt;4. Last but by no means the least Tutorials from the jQuery Team. &lt;a href="http://docs.jquery.com/Tutorials"&gt;(Click Here)&lt;/a&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-5924451625750375478?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/5924451625750375478/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2008/09/jquery-time.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/5924451625750375478'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/5924451625750375478'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2008/09/jquery-time.html' title='JQuery Time'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-7767752139641800657</id><published>2008-09-29T11:15:00.007+05:30</published><updated>2009-10-05T17:07:05.349+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Custom DateTime Formats'/><category scheme='http://www.blogger.com/atom/ns#' term='DateTime Formats'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='DateTime Format Strings'/><title type='text'>DateTime Format Strings</title><content type='html'>Been googling about common DateTime format strings.&lt;br /&gt;Surprisingly, very few relevant ones came up.&lt;br /&gt;So decided to make a post of the formats I got for future reference&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="csharp"&gt;&lt;br /&gt;&lt;br /&gt;DateTime.Now; //5/16/2006 1:05:13 AM&lt;br /&gt;DateTime.Now.ToString(); //5/16/2006 1:05:13 AM&lt;br /&gt;DateTime.Now.ToShortTimeString() //11:40 AM&lt;br /&gt;DateTime.Now.ToShortDateString() //5/16/2006&lt;br /&gt;DateTime.Now.ToLongTimeString() //11:40:13 AM&lt;br /&gt;DateTime.Now.ToLongDateString() //Tuesday, May 16, 2006&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Examples of DateTime for Given Formats&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="csharp"&gt;&lt;br /&gt;&lt;br /&gt;DateTime.Now.ToString("dddd, MMMM dd yyyy") // Tuesday, May 16 2006&lt;br /&gt;DateTime.Now.ToString("ddd, MMM d "'"yy") // Tue, May 16 '06&lt;br /&gt;DateTime.Now.ToString("dddd, MMMM dd") // Tuesday, May 16&lt;br /&gt;DateTime.Now.ToString("M/yy") // 5/06&lt;br /&gt;DateTime.Now.ToString("dd-MM-yy") // 16-05-06&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Courtesy : An article from &lt;a href="http://www.dotnetspider.com/resources/1622-Briefly-About-System-DateTime-Namespace.aspx"&gt;DOTNET Spider&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-7767752139641800657?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/7767752139641800657/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2008/09/datetime-format-strings.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/7767752139641800657'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/7767752139641800657'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2008/09/datetime-format-strings.html' title='DateTime Format Strings'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-8214594080197297540</id><published>2008-08-28T15:02:00.007+05:30</published><updated>2009-10-05T17:07:19.121+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='URL Checker'/><category scheme='http://www.blogger.com/atom/ns#' term='URL Exist'/><category scheme='http://www.blogger.com/atom/ns#' term='Check for 404'/><category scheme='http://www.blogger.com/atom/ns#' term='ASPX'/><category scheme='http://www.blogger.com/atom/ns#' term='URL Check'/><title type='text'>Check if a URL actually exists</title><content type='html'>We have seen many validations for URLs.&lt;br /&gt;But what to do if the requirement is like to check whether a URL is in the NET.&lt;br /&gt;In other words, how can one knows the URL given has not returned a 404 error?&lt;br /&gt;&lt;br /&gt;Here's the code&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="csharp"&gt;&lt;br /&gt;&lt;br /&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;/// Checks the status of the specified URL.&lt;br /&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;/// &amp;lt;param name=&amp;quot;strURL&amp;quot;&amp;gt;The URL that needs to be checked&amp;lt;/param&amp;gt;&lt;br /&gt;/// &amp;lt;returns&amp;gt;True if the URL exists&amp;lt;/returns&amp;gt;&lt;br /&gt;&lt;br /&gt;public bool IsURLValid(string strURL)&lt;br /&gt;{&lt;br /&gt;    string strResponse = &amp;quot;&amp;quot;;&lt;br /&gt;    try&lt;br /&gt;    {&lt;br /&gt;        string pattern = @&amp;quot;((http|ftp|https):\/\/w{3}[\d]*.|(http|ftp|https):\/\/|w{3}[\d]*.)([\w\d\._\-#\(\)\[\]\\,;:]+@[\w\d\._\-#\(\)\[\]\\,;:])?([a-z0-9]+.)*[a-z\-0-9]+.([a-z]{2,3})?[a-z]{2,6}(:[0-9]+)?(\/[\/a-z0-9\._\-,]+)*[a-z0-9\-_\.\s\%]+(\?[a-z0-9=%&amp;amp;\.\-,#]+)?&amp;quot;;&lt;br /&gt;//validatng url in case if it hasn't been validated earlier&lt;br /&gt;        if(Regex.IsMatch(strURL,pattern))&lt;br /&gt;        {&lt;br /&gt;            WebRequest request = HttpWebRequest.Create(strURL);&lt;br /&gt;            request.Timeout = 5000;&lt;br /&gt;            strResponse = ((HttpWebResponse)request.GetResponse()).StatusCode.ToString();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    catch(Exception exp)&lt;br /&gt;    {&lt;br /&gt;        strResponse = &amp;quot;&amp;quot;;&lt;br /&gt;    }&lt;br /&gt;    return (strResponse==&amp;quot;OK&amp;quot;)? true: false;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Does the work, but not very classy.&lt;br /&gt;Any better ideas?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-8214594080197297540?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/8214594080197297540/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2008/08/check-if-url-actually-exists.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/8214594080197297540'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/8214594080197297540'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2008/08/check-if-url-actually-exists.html' title='Check if a URL actually exists'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-1061828599412197981</id><published>2008-08-16T12:23:00.007+05:30</published><updated>2010-12-30T16:52:41.917+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='?? Operator'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Coalesce Operator'/><category scheme='http://www.blogger.com/atom/ns#' term='Ternary Operator'/><title type='text'>The Coalesce Operator (The ?? Operator in C#)e</title><content type='html'>The Conventional Way&lt;br /&gt;&lt;pre class="brush:csharp"&gt;if (obj1 != null)&lt;br /&gt;{&lt;br /&gt;objOut = obj1;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;objOut = obj2;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The Ternary Operator&lt;br /&gt;&lt;pre class="brush:csharp"&gt;objOut = (obj1 != null) ? obj1 : obj2;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The &lt;strong&gt;Coalesce&lt;/strong&gt; Operator Way&lt;br /&gt;&lt;pre class="brush:csharp"&gt;objOut = obj1 ?? obj2;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The Extended Coalesce Operator&lt;br /&gt;&lt;br /&gt;The Conventional Way&lt;br /&gt;&lt;pre class="brush:csharp"&gt;if (obj1 != null)&lt;br /&gt;{&lt;br /&gt;return obj1;&lt;br /&gt;}&lt;br /&gt;else if (obj2 != null)&lt;br /&gt;{&lt;br /&gt;return obj2;&lt;br /&gt;}&lt;br /&gt;else if (obj3 != null)&lt;br /&gt;{&lt;br /&gt;return obj3;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;return null;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The &lt;strong&gt;Coalesce&lt;/strong&gt; Operator Way&lt;br /&gt;&lt;pre class="brush:csharp"&gt;return obj1 ?? obj2 ?? obj3;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;As a useful replacement to the Ternary Operator &lt;br /&gt;&lt;br /&gt;The Ternary Operator Way&lt;br /&gt;&lt;pre class="brush:csharp"&gt;obj = (obj != null)? obj : objNew;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The &lt;strong&gt;Coalesce&lt;/strong&gt; Operator Way&lt;br /&gt;&lt;pre class="brush:csharp"&gt;obj = obj ?? objNew;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Then why is not used more? I think cos its got a tough name.[:)]&lt;br /&gt;How do you pronounce it?&lt;br /&gt;&lt;br /&gt;I LOVE C#&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-1061828599412197981?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/1061828599412197981/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2008/08/coalsce-operator-operator-in-c.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/1061828599412197981'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/1061828599412197981'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2008/08/coalsce-operator-operator-in-c.html' title='The Coalesce Operator (The ?? Operator in C#)e'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-1660490416433422471</id><published>2008-08-16T10:59:00.011+05:30</published><updated>2009-10-05T17:08:09.349+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='there is no attribute &quot;border&quot;'/><category scheme='http://www.blogger.com/atom/ns#' term='validations'/><category scheme='http://www.blogger.com/atom/ns#' term='W3c Validation'/><category scheme='http://www.blogger.com/atom/ns#' term='App_Browsers'/><title type='text'>Resolving W3C Validation Issues</title><content type='html'>For those who are wondering why should one bother with W3C Validations,&lt;br /&gt;please read &lt;a href="http://validator.w3.org/docs/why.html"&gt;Why should we Validate our WebSites?&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;When validating your website using W3C some weird errors might occur&lt;br /&gt;&lt;br /&gt;An Example is&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;there is no attribute "border"&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;even if you haven't given the border attribute&lt;br /&gt;&lt;br /&gt;The Reason&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;The ASP.NET engines sees the W3C validator as down-level browser and renders&lt;br /&gt; non-XHTML compliant code. Your code is most likely fine. The problem is with &lt;br /&gt;ASP.NET. &lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Solution(Step Wise)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1.Right Click on your Solution Explorer&lt;br /&gt;2.Click on Add ASP.NET Folder ---&gt; App_Browsers&lt;br /&gt;3.Now Click on App_Browsers ---&gt; Add New Item&lt;br /&gt;4.A dialog Box now pops up with some Visual Studio Installed Templates.&lt;br /&gt;  Select the Browser File Template from there, change the name as W3CValidations.browser(any other convenient name also) and Click on the Add Button&lt;br /&gt;5.Delete the whole XML MarkUp code inside the W3CValidations.browser&lt;br /&gt;6.Place the following code instead&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="xml"&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;browsers&amp;gt;&lt;br /&gt;  &amp;lt;!--&lt;br /&gt;  Browser capability file for the w3c validator&lt;br /&gt;  &lt;br /&gt;  sample UA: &amp;quot;W3C_Validator/1.305.2.148 libwww-perl/5.803&amp;quot;&lt;br /&gt;  --&amp;gt;&lt;br /&gt;  &amp;lt;browser id=&amp;quot;w3cValidator&amp;quot; parentID=&amp;quot;default&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;identification&amp;gt;&lt;br /&gt;      &amp;lt;userAgent match=&amp;quot;^W3C_Validator&amp;quot; /&amp;gt;&lt;br /&gt;    &amp;lt;/identification&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;capture&amp;gt;&lt;br /&gt;      &amp;lt;userAgent match=&amp;quot;^W3C_Validator/(?'version'(?'major'\d+)(?'minor'\.\d+)\w*).*&amp;quot; /&amp;gt;&lt;br /&gt;    &amp;lt;/capture&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;capabilities&amp;gt;&lt;br /&gt;      &amp;lt;capability name=&amp;quot;browser&amp;quot; value=&amp;quot;w3cValidator&amp;quot; /&amp;gt;&lt;br /&gt;      &amp;lt;capability name=&amp;quot;majorversion&amp;quot; value=&amp;quot;${major}&amp;quot; /&amp;gt;&lt;br /&gt;      &amp;lt;capability name=&amp;quot;minorversion&amp;quot; value=&amp;quot;${minor}&amp;quot; /&amp;gt;&lt;br /&gt;      &amp;lt;capability name=&amp;quot;version&amp;quot; value=&amp;quot;${version}&amp;quot; /&amp;gt;&lt;br /&gt;      &amp;lt;capability name=&amp;quot;w3cdomversion&amp;quot; value=&amp;quot;1.0&amp;quot; /&amp;gt;&lt;br /&gt;      &amp;lt;capability name=&amp;quot;xml&amp;quot; value=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;      &amp;lt;capability name=&amp;quot;tagWriter&amp;quot; value=&amp;quot;System.Web.UI.HtmlTextWriter&amp;quot; /&amp;gt;      &lt;br /&gt;    &amp;lt;/capabilities&amp;gt;&lt;br /&gt;  &amp;lt;/browser&amp;gt;&lt;br /&gt;&amp;lt;/browsers&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;7.Now upload this Folder and File to your Hosting Service&lt;br /&gt;8.Re Validate using &lt;a href="http://validator.w3.org/"&gt;W3C Validator&lt;/a&gt;&lt;br /&gt;9.Bingo! You got a Clean Validation Certificate.&lt;br /&gt;10. Show off the Validation Certificate to all those who cares [:)]&lt;br /&gt;&lt;br /&gt;Courtesy&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;a href="http://digitalcolony.com/2008/02/w3c-validation-for-aspnet-data-controls.aspx"&gt;Link at DigitalColony.com&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://idunno.org/archive/2005/01/01/216.aspx"&gt;Link at idunno.org&lt;/a&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Happy Coding!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-1660490416433422471?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/1660490416433422471/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2008/08/resolving-w3c-validation-issues.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/1660490416433422471'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/1660490416433422471'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2008/08/resolving-w3c-validation-issues.html' title='Resolving W3C Validation Issues'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-7030691865195615823</id><published>2008-08-08T11:43:00.011+05:30</published><updated>2011-05-26T09:03:19.277+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='gridview with javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='nested gridview'/><title type='text'>Nested GridView with Paging for Child Grid</title><content type='html'>I have a post called &lt;a href="http://www.fun2code.blogspot.com/2008/07/nested-gridview.html"&gt;Nested GridView using JavaScript&lt;/a&gt; in this same blog.&lt;br /&gt;&lt;br /&gt;A guy at &lt;a href="http://forums.asp.net/p/1301990/2544935.aspx#2543113"&gt;ASP.NET Forums&lt;/a&gt; asked how to implement paging for the child grid and this is what made me make a post on this.&lt;br /&gt;&lt;br /&gt;Just change the ASPX.CS like this.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:c-sharp"&gt;&lt;br /&gt;    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (e.Row.RowType == DataControlRowType.DataRow)&lt;br /&gt;        {&lt;br /&gt;            BindGridToDS(GridView1.DataKeys[e.Row.RowIndex].Value.ToString(), (GridView)e.Row.FindControl("GridView2"));&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)&lt;br /&gt;    {&lt;br /&gt;        GridView gvwChild = ((GridView)sender);&lt;br /&gt;        GridViewRow gvRowParent = ((GridView)sender).Parent.Parent as GridViewRow;&lt;br /&gt;&lt;br /&gt;        gvwChild.PageIndex = e.NewPageIndex;&lt;br /&gt;        BindGridToDS(GridView1.DataKeys[gvRowParent.RowIndex].Value.ToString(), gvwChild);&lt;br /&gt;&lt;br /&gt;        //show the div again after postback&lt;br /&gt;        string strDIVID = "div" + GridView1.DataKeys[gvRowParent.RowIndex].Value.ToString();&lt;br /&gt;        string cScript = "&lt;script type=\"text/javascript\"&gt;ShowChildGrid('" + strDIVID + "');&lt;/script&gt;";&lt;br /&gt;        ClientScript.RegisterStartupScript(typeof(Page), "clientscript", cScript);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private void BindGridToDS(string strCustomerID, GridView gv)&lt;br /&gt;    {&lt;br /&gt;        SqlDataSource dbSrc = new SqlDataSource();&lt;br /&gt;        dbSrc.ConnectionString = ConfigurationManager.ConnectionStrings["NorthWind"].ConnectionString;&lt;br /&gt;        dbSrc.SelectCommand = "SELECT * FROM Orders WHERE CustomerID = '" + strCustomerID + "' ORDER BY OrderDate";&lt;br /&gt;        gv.DataSource = dbSrc;&lt;br /&gt;        gv.DataBind();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Happy Coding!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-7030691865195615823?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/7030691865195615823/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2008/08/nested-gridview-with-paging-for-child.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/7030691865195615823'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/7030691865195615823'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2008/08/nested-gridview-with-paging-for-child.html' title='Nested GridView with Paging for Child Grid'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-2748595787727718450</id><published>2008-08-05T15:34:00.008+05:30</published><updated>2010-12-06T19:52:23.301+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='image data type gridview'/><title type='text'>Display Images stored as Image in GridView</title><content type='html'>Suppose we have a table in DB named "Images"&lt;br /&gt;The data inside it are&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;img_id(int)                  ---&gt;   the id of the image&lt;br /&gt;img_name(varchar(50))        ---&gt;   the name given to image&lt;br /&gt;img_data(image)              ---&gt;   the image stored as bit array&lt;br /&gt;img_contenttype(varchar(20)) ---&gt;   like image/png, image/jpeg and all&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Our requirement is to show the images in a GridView&lt;br /&gt;&lt;br /&gt;Here's the ASPX&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:xml"&gt;&lt;br /&gt;&amp;lt;asp:GridView ID=&amp;quot;gvwImages&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;AutoGenerateColumns=&amp;quot;false&amp;quot; &lt;br /&gt;DataSourceID=&amp;quot;dsImages&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;Columns&amp;gt;&lt;br /&gt;&amp;lt;asp:TemplateField HeaderText=&amp;quot;Name&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;%--field img_name is the name given to image--%&amp;gt;&lt;br /&gt;&amp;lt;asp:Label ID=&amp;quot;lblName&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;Text='&amp;lt;%#Eval(&amp;quot;img_name&amp;quot;) %&amp;gt;'&amp;gt;&lt;br /&gt;&amp;lt;/asp:Label&amp;gt;&lt;br /&gt;&amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;&amp;lt;asp:TemplateField HeaderText=&amp;quot;Image&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;%--here field img_id is the id of the image--%&amp;gt;&lt;br /&gt;&amp;lt;asp:Image ID=&amp;quot;Image1&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;ImageUrl='&amp;lt;%# &amp;quot;Handler.ashx?id=&amp;quot; + Eval(&amp;quot;img_id&amp;quot;) %&amp;gt;' /&amp;gt;&lt;br /&gt;&amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;&amp;lt;/Columns&amp;gt;&lt;br /&gt;&amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;&amp;lt;asp:SqlDataSource ID=&amp;quot;dsImages&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;ConnectionString='&amp;lt;%$ConnectionStrings: your conn string %&amp;gt;'&lt;br /&gt;SelectCommand=&amp;quot;Select img_id,img_name from Images&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/asp:SqlDataSource&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Here inside ImageUrl we have given Handler.ashx.&lt;br /&gt;Since we dont have one, create one.&lt;br /&gt;Go to Add New Item. select Generic Handler and click OK.&lt;br /&gt;&lt;br /&gt;Inside the Handler.ashx, paste this code&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:csharp"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Configuration;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Data.SqlClient;&lt;br /&gt;&lt;br /&gt;public class Handler : IHttpHandler&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public bool IsReusable&lt;br /&gt;{&lt;br /&gt;get { return false; }&lt;br /&gt;}&lt;br /&gt;public void ProcessRequest(HttpContext context)&lt;br /&gt;{&lt;br /&gt;SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["LoginCon"].ConnectionString);&lt;br /&gt;myConnection.Open();&lt;br /&gt;//here field img_data is the content of the image (type image in DB)&lt;br /&gt;//field img_contenttype is the type of the image (optional)&lt;br /&gt;string sql = "Select img_data,img_contenttype from Images where img_id=@ImageId";&lt;br /&gt;SqlCommand cmd = new SqlCommand(sql, myConnection);&lt;br /&gt;cmd.Parameters.Add("@ImageId", SqlDbType.Int).Value = context.Request.QueryString["id"];&lt;br /&gt;cmd.Prepare();&lt;br /&gt;SqlDataReader dr = cmd.ExecuteReader();&lt;br /&gt;dr.Read();&lt;br /&gt;context.Response.ContentType = dr["img_contenttype"].ToString();&lt;br /&gt;context.Response.BinaryWrite((byte[])dr["img_data"]);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Simple enough right?&lt;br /&gt;&lt;br /&gt;Now if you wanna test it do it using Northwind DB.&lt;br /&gt;Take the "Employees" table inside it and try to diplay the field "Photo"&lt;br /&gt;10 out of 10, it wont work in your Page. [:)]&lt;br /&gt;Suprised?&lt;br /&gt;The reason is that the images stored in Northwind DB has OLE Header.&lt;br /&gt;The header length is invariably 78 bytes.&lt;br /&gt;So if we remove the first 78 bytes we can view images from Northwind too.&lt;br /&gt;&lt;br /&gt;Here goes the special Handler.ashx for Northwind DB.(Table used ---&gt; Employees)&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:csharp"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Configuration;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Data.SqlClient;&lt;br /&gt;&lt;br /&gt;public class Handler : IHttpHandler&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public bool IsReusable&lt;br /&gt;{&lt;br /&gt;get { return false; }&lt;br /&gt;}&lt;br /&gt;public void ProcessRequest(HttpContext context)&lt;br /&gt;{&lt;br /&gt;//context.Response.ContentType = "text/plain";&lt;br /&gt;//context.Response.Write("Hello World");&lt;br /&gt;SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString);&lt;br /&gt;sqlConnection.Open();&lt;br /&gt;string sql = " Select Photo from Employees where EmployeeID=@EmpId";&lt;br /&gt;SqlCommand cmd = new SqlCommand(sql, sqlConnection);&lt;br /&gt;cmd.Parameters.Add("@EmpId", SqlDbType.Int).Value = context.Request.QueryString["id"];&lt;br /&gt;cmd.Prepare();&lt;br /&gt;SqlDataReader dr = cmd.ExecuteReader();&lt;br /&gt;dr.Read();&lt;br /&gt;// Output the binary data&lt;br /&gt;// But first we need to strip out the OLE header&lt;br /&gt;byte[] thePicture = (byte[])dr["Photo"];&lt;br /&gt;const int OleHeaderLength = 78;&lt;br /&gt;int strippedImageLength = thePicture.Length - OleHeaderLength;&lt;br /&gt;byte[] strippedImageData = new byte[strippedImageLength];&lt;br /&gt;Array.Copy(thePicture, OleHeaderLength, strippedImageData, 0, strippedImageLength);&lt;br /&gt;context.Response.BinaryWrite(strippedImageData);&lt;br /&gt;// context.Response.BinaryWrite((byte[])dr["Photo"]);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Happy Coding!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-2748595787727718450?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/2748595787727718450/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2008/08/display-images-stored-as-image-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/2748595787727718450'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/2748595787727718450'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2008/08/display-images-stored-as-image-in.html' title='Display Images stored as Image in GridView'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-3987920396992593982</id><published>2008-07-26T12:42:00.015+05:30</published><updated>2010-12-09T16:40:45.461+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='listview paging'/><title type='text'>Paging in ListView</title><content type='html'>Paging in ListView is pretty different from Paging in GridView.&lt;br /&gt;We page data on a ListView using DataPager.&lt;br /&gt;Its a joyful ride that has so many features we have dreamed of&lt;br /&gt;&lt;div style="overflow:auto;"&gt;&lt;img src="https://sites.google.com/site/fun2code/Home/listview_paging.PNG"alt="ListView with Top and Bottom Pagers attached to it" title="ListView with Top and Bottom Pagers attached to it"/&gt;&lt;br /&gt;&lt;/div&gt;&lt;blockquote&gt;Paging in GridView is with a twist and not an extension of gridview paging.&lt;br /&gt;It uses the ListView event for Paging called&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;"OnPagePropertiesChanging"&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;Here is an example of doing it using two datapagers so that paging gets displayed&lt;br /&gt;both on top and bottom of the page (google serach page style)&lt;br /&gt;As used at almost all my examples, the database Northwind is used.&lt;br /&gt;&lt;br /&gt;In ASPX&lt;br /&gt;&lt;br /&gt;The Top Pager&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:xhtml"&gt;&amp;lt;asp:UpdatePanel ID=&amp;quot;updPanel&amp;quot; runat=&amp;quot;server&amp;quot; UpdateMode=&amp;quot;Conditional&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;ContentTemplate&amp;gt;&lt;br /&gt;        &amp;lt;div class=&amp;quot;pager&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;asp:DataPager ID=&amp;quot;pgrTopDetails&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;                    PageSize=&amp;quot;10&amp;quot;&lt;br /&gt;                    PagedControlID=&amp;quot;ListView1&amp;quot;&amp;gt;&lt;br /&gt;                &amp;lt;Fields&amp;gt;&lt;br /&gt;                    &amp;lt;asp:NextPreviousPagerField ButtonCssClass=&amp;quot;command&amp;quot;&lt;br /&gt;                                        PreviousPageText=&amp;quot;Previous&amp;quot;&lt;br /&gt;                                        RenderDisabledButtonsAsLabels=&amp;quot;true&amp;quot;&lt;br /&gt;                                        RenderNonBreakingSpacesBetweenControls=&amp;quot;true&amp;quot;&lt;br /&gt;                                        ShowFirstPageButton=&amp;quot;false&amp;quot;&lt;br /&gt;                                        ShowNextPageButton=&amp;quot;false&amp;quot;&lt;br /&gt;                                        ShowLastPageButton=&amp;quot;false&amp;quot;&lt;br /&gt;                                        ShowPreviousPageButton=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;                    &amp;lt;asp:NumericPagerField ButtonCount=&amp;quot;10&amp;quot;&lt;br /&gt;                                        NumericButtonCssClass=&amp;quot;command&amp;quot; &lt;br /&gt;                                        CurrentPageLabelCssClass=&amp;quot;current&amp;quot; &lt;br /&gt;                                        NextPreviousButtonCssClass=&amp;quot;command&amp;quot;&lt;br /&gt;                                        RenderNonBreakingSpacesBetweenControls=&amp;quot;true&amp;quot;/&amp;gt; &lt;br /&gt;                    &amp;lt;asp:NextPreviousPagerField ButtonCssClass=&amp;quot;command&amp;quot;&lt;br /&gt;                                        NextPageText=&amp;quot;Next&amp;quot;&lt;br /&gt;                                        RenderDisabledButtonsAsLabels=&amp;quot;true&amp;quot;&lt;br /&gt;                                        ShowFirstPageButton=&amp;quot;false&amp;quot;&lt;br /&gt;                                        ShowPreviousPageButton=&amp;quot;false&amp;quot;&lt;br /&gt;                                        ShowNextPageButton=&amp;quot;true&amp;quot;&lt;br /&gt;                                        ShowLastPageButton=&amp;quot;false&amp;quot; /&amp;gt;&lt;br /&gt;                &amp;lt;/Fields&amp;gt;&lt;br /&gt;            &amp;lt;/asp:DataPager&amp;gt;&lt;br /&gt;        &amp;lt;/div&amp;gt;&lt;br /&gt;        &amp;lt;asp:ListView ID=&amp;quot;ListView1&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;                    DataKeyNames=&amp;quot;ProductID&amp;quot;&lt;br /&gt;                    OnPagePropertiesChanging=&amp;quot;ListView1_PagePropertiesChanging&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;LayoutTemplate&amp;gt;&lt;br /&gt;                &amp;lt;table class=&amp;quot;datatable&amp;quot;&amp;gt;&lt;br /&gt;                    &amp;lt;tr&amp;gt;&lt;br /&gt;                        &amp;lt;th&amp;gt;ID&amp;lt;/th&amp;gt;&lt;br /&gt;                        &amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;&lt;br /&gt;                        &amp;lt;th&amp;gt;Quantity&amp;lt;/th&amp;gt;&lt;br /&gt;                        &amp;lt;th&amp;gt;Unit Price&amp;lt;/th&amp;gt;&lt;br /&gt;                        &amp;lt;th&amp;gt;In Stock&amp;lt;/th&amp;gt;&lt;br /&gt;                        &amp;lt;th&amp;gt;On Order&amp;lt;/th&amp;gt;&lt;br /&gt;                    &amp;lt;/tr&amp;gt;&lt;br /&gt;                    &amp;lt;tr id=&amp;quot;itemPlaceholder&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;                &amp;lt;/table&amp;gt;&lt;br /&gt;            &amp;lt;/LayoutTemplate&amp;gt;&lt;br /&gt;            &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;                &amp;lt;tr class=&amp;quot;row&amp;quot;&amp;gt;&lt;br /&gt;                    &amp;lt;td&amp;gt;&amp;lt;%# Eval(&amp;quot;ProductID&amp;quot;) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;                    &amp;lt;td&amp;gt;&amp;lt;%# Eval(&amp;quot;ProductName&amp;quot;) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;                    &amp;lt;td&amp;gt;&amp;lt;%# Eval(&amp;quot;QuantityPerUnit&amp;quot;) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;                    &amp;lt;td&amp;gt;&amp;lt;%# Eval(&amp;quot;UnitPrice&amp;quot;) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;                    &amp;lt;td&amp;gt;&amp;lt;%# Eval(&amp;quot;UnitsInStock&amp;quot;) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;                    &amp;lt;td&amp;gt;&amp;lt;%# Eval(&amp;quot;UnitsOnOrder&amp;quot;) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;                &amp;lt;/tr&amp;gt;&lt;br /&gt;            &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;        &amp;lt;/asp:ListView&amp;gt;&lt;br /&gt;        &amp;lt;div class=&amp;quot;pager&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;asp:DataPager ID=&amp;quot;pgrBottomDetails&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;                        PageSize=&amp;quot;10&amp;quot;&lt;br /&gt;                        PagedControlID=&amp;quot;ListView1&amp;quot;&amp;gt;&lt;br /&gt;                &amp;lt;Fields&amp;gt;&lt;br /&gt;                    &amp;lt;asp:NextPreviousPagerField ButtonCssClass=&amp;quot;command&amp;quot;&lt;br /&gt;                                        PreviousPageText=&amp;quot;Previous&amp;quot;&lt;br /&gt;                                        RenderDisabledButtonsAsLabels=&amp;quot;true&amp;quot;&lt;br /&gt;                                        RenderNonBreakingSpacesBetweenControls=&amp;quot;true&amp;quot;&lt;br /&gt;                                        ShowFirstPageButton=&amp;quot;false&amp;quot;&lt;br /&gt;                                        ShowNextPageButton=&amp;quot;false&amp;quot;&lt;br /&gt;                                        ShowLastPageButton=&amp;quot;false&amp;quot;&lt;br /&gt;                                        ShowPreviousPageButton=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;                    &amp;lt;asp:NumericPagerField ButtonCount=&amp;quot;10&amp;quot;&lt;br /&gt;                                        NumericButtonCssClass=&amp;quot;command&amp;quot; &lt;br /&gt;                                        CurrentPageLabelCssClass=&amp;quot;current&amp;quot; &lt;br /&gt;                                        NextPreviousButtonCssClass=&amp;quot;command&amp;quot;&lt;br /&gt;                                        RenderNonBreakingSpacesBetweenControls=&amp;quot;true&amp;quot;/&amp;gt; &lt;br /&gt;                    &amp;lt;asp:NextPreviousPagerField ButtonCssClass=&amp;quot;command&amp;quot;&lt;br /&gt;                                        NextPageText=&amp;quot;Next&amp;quot;&lt;br /&gt;                                        RenderDisabledButtonsAsLabels=&amp;quot;true&amp;quot;&lt;br /&gt;                                        ShowFirstPageButton=&amp;quot;false&amp;quot;&lt;br /&gt;                                        ShowPreviousPageButton=&amp;quot;false&amp;quot;&lt;br /&gt;                                        ShowNextPageButton=&amp;quot;true&amp;quot;&lt;br /&gt;                                        ShowLastPageButton=&amp;quot;false&amp;quot; /&amp;gt;&lt;br /&gt;                    &amp;lt;asp:TemplatePagerField&amp;gt;&lt;br /&gt;                        &amp;lt;PagerTemplate&amp;gt;&lt;br /&gt;                            &amp;lt;br /&amp;gt;&lt;br /&gt;                            Displaying&amp;amp;nbsp;&amp;lt;%# Container.StartRowIndex + 1 %&amp;gt;&amp;amp;nbsp;to&amp;amp;nbsp;&lt;br /&gt;                            &amp;lt;%# Container.StartRowIndex + Container.PageSize %&amp;gt;&amp;amp;nbsp;of&amp;amp;nbsp;&lt;br /&gt;                            (&amp;lt;strong&amp;gt;&amp;lt;%# Container.TotalRowCount%&amp;gt;&amp;lt;/strong&amp;gt;) Profiles Found.&lt;br /&gt;                        &amp;lt;/PagerTemplate&amp;gt;&lt;br /&gt;                    &amp;lt;/asp:TemplatePagerField&amp;gt;&lt;br /&gt;                &amp;lt;/Fields&amp;gt;&lt;br /&gt;            &amp;lt;/asp:DataPager&amp;gt;&lt;br /&gt;        &amp;lt;/div&amp;gt;                             &lt;br /&gt;    &amp;lt;/ContentTemplate&amp;gt;&lt;br /&gt;&amp;lt;/asp:UpdatePanel&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In ASPX.CS&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:csharp"&gt;private static NorthwindClassesDataContext database;&lt;br /&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    if (!IsPostBack)&lt;br /&gt;    {&lt;br /&gt;        database = new NorthwindClassesDataContext(ConfigurationManager&lt;br /&gt;                        .ConnectionStrings["NorthwindConnectionString"]&lt;br /&gt;                        .ConnectionString);&lt;br /&gt;        BindListView();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;protected void ListView1_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)&lt;br /&gt;{&lt;br /&gt;    this.pgrTopDetails.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);&lt;br /&gt;    this.pgrBottomDetails.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);&lt;br /&gt;    //custom function to bind your listview&lt;br /&gt;    BindListView();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private void BindListView()&lt;br /&gt;{&lt;br /&gt;    ListView1.DataSource = database.Products.OrderBy(p =&gt; p.ProductID);&lt;br /&gt;    ListView1.DataBind();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a href="https://sites.google.com/site/fun2code/Home/ListViewPager.zip"&gt;Download Source Code(16kb)&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Simple enough, right?&lt;br /&gt;Happy Coding!&lt;br /&gt;&lt;br /&gt;P.S: The above shown &lt;a target="_blank" href="http://mattberseth.com/blog/2008/04/building_a_vs2008_styled_grid.html"&gt;style is a shameless port of gridview style by Matt Berseth&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;He is a wonderful coder with so many superb wonders done on DataPresentation Controls at .NET&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-3987920396992593982?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/3987920396992593982/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2008/07/paging-in-listview.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/3987920396992593982'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/3987920396992593982'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2008/07/paging-in-listview.html' title='Paging in ListView'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-1160831711615961157</id><published>2008-07-17T17:07:00.013+05:30</published><updated>2011-05-26T09:03:25.105+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript gridview'/><category scheme='http://www.blogger.com/atom/ns#' term='javascript nesting gridview'/><category scheme='http://www.blogger.com/atom/ns#' term='gridview nesting'/><category scheme='http://www.blogger.com/atom/ns#' term='nested gridview'/><category scheme='http://www.blogger.com/atom/ns#' term='child parent gridivew'/><title type='text'>Nested GridView</title><content type='html'>Sometimes there will be tables in databases corresponding to another ones&lt;br /&gt;Suppose we have a table named Customer and another named Orders(made by each customer)&lt;br /&gt;In that case it will be better to use &lt;span style="font-weight:bold;"&gt;Nested GridView&lt;/span&gt;.&lt;br /&gt;Here we are making it a little fancier using &lt;span style="font-weight:bold;"&gt;Javascript&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Here is a &lt;span style="font-weight:bold;"&gt;ScreenShot&lt;/span&gt; of the&lt;span style="font-weight:bold;"&gt; Nested GridView&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_uM-oszK-kVo/SH8v94tymXI/AAAAAAAAAv8/-Hxx5Cmsxjg/s1600-h/nestedgridview.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;" src="http://bp2.blogger.com/_uM-oszK-kVo/SH8v94tymXI/AAAAAAAAAv8/-Hxx5Cmsxjg/s320/nestedgridview.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5223946833016035698" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Prequisites&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1.Create a folder in your project called &lt;span style="font-weight:bold;"&gt;"Images"&lt;/span&gt; and put two images&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;arrowright.jpg&lt;/span&gt; and &lt;span style="font-weight:bold;"&gt;arrowdown.jpg&lt;/span&gt; which are arrows pointing to the defined directions.&lt;br /&gt;&lt;br /&gt;2.Create a &lt;span style="font-weight:bold;"&gt;ConnectionString&lt;/span&gt; named &lt;span style="font-weight:bold;"&gt;"NorthWindConnectionString"&lt;/span&gt; in the &lt;span style="font-weight:bold;"&gt;web.config&lt;/span&gt; pointing to the Northwind DB in your system&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;In ASPX Page&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush:html"&gt;&amp;lt;asp:GridView ID=&amp;quot;GridView1&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;AllowPaging=&amp;quot;True&amp;quot;&lt;br /&gt;AutoGenerateColumns=&amp;quot;False&amp;quot;&lt;br /&gt;DataKeyNames=&amp;quot;CustomerID&amp;quot;&lt;br /&gt;DataSourceID=&amp;quot;SqlDataSource1&amp;quot;&lt;br /&gt;PageSize=&amp;quot;20&amp;quot;&lt;br /&gt;OnRowDataBound=&amp;quot;GridView1_RowDataBound&amp;quot; &lt;br /&gt;CellPadding=&amp;quot;4&amp;quot; &lt;br /&gt;ForeColor=&amp;quot;#333333&amp;quot; &lt;br /&gt;GridLines=&amp;quot;None&amp;quot;&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;HeaderStyle BackColor=&amp;quot;#5D7B9D&amp;quot; Font-Bold=&amp;quot;True&amp;quot; ForeColor=&amp;quot;White&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;RowStyle BackColor=&amp;quot;#F7F6F3&amp;quot; ForeColor=&amp;quot;#333333&amp;quot; /&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;Columns&amp;gt;&lt;br /&gt;&amp;lt;asp:TemplateField&amp;gt;&lt;br /&gt;&amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;a href=&amp;quot;javascript:ShowChildGrid('div&amp;lt;%# Eval(&amp;quot;CustomerID&amp;quot;) %&amp;gt;');&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;img id=&amp;quot;imgdiv&amp;lt;%# Eval(&amp;quot;CustomerID&amp;quot;) %&amp;gt;&amp;quot; &lt;br /&gt;alt=&amp;quot;Click to show/hide orders&amp;quot; &lt;br /&gt;border=&amp;quot;0&amp;quot; &lt;br /&gt;src=&amp;quot;Images/arrowright.jpg&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;&amp;lt;asp:BoundField DataField=&amp;quot;CompanyName&amp;quot; HeaderText=&amp;quot;CompanyName&amp;quot; SortExpression=&amp;quot;CompanyName&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;asp:BoundField DataField=&amp;quot;ContactName&amp;quot; HeaderText=&amp;quot;ContactName&amp;quot; SortExpression=&amp;quot;ContactName&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;asp:BoundField DataField=&amp;quot;Address&amp;quot; HeaderText=&amp;quot;Address&amp;quot; SortExpression=&amp;quot;Address&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;asp:BoundField DataField=&amp;quot;City&amp;quot; HeaderText=&amp;quot;City&amp;quot; SortExpression=&amp;quot;City&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;asp:BoundField DataField=&amp;quot;PostalCode&amp;quot; HeaderText=&amp;quot;PostalCode&amp;quot; SortExpression=&amp;quot;PostalCode&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;asp:BoundField DataField=&amp;quot;Phone&amp;quot; HeaderText=&amp;quot;Phone&amp;quot; SortExpression=&amp;quot;Phone&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;asp:TemplateField&amp;gt;&lt;br /&gt;&amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&lt;br /&gt;&amp;lt;td colspan=&amp;quot;100%&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;div&amp;lt;%# Eval(&amp;quot;CustomerID&amp;quot;) %&amp;gt;&amp;quot; style=&amp;quot;display:none;position:relative;left:25px;&amp;quot; &amp;gt;&lt;br /&gt;&amp;lt;asp:GridView ID=&amp;quot;GridView2&amp;quot; runat=&amp;quot;server&amp;quot;&lt;br /&gt;AutoGenerateColumns=&amp;quot;false&amp;quot;&lt;br /&gt;DataKeyNames=&amp;quot;OrderID&amp;quot;&lt;br /&gt;EmptyDataText=&amp;quot;No orders for this customer.&amp;quot;&lt;br /&gt;Width=&amp;quot;80%&amp;quot; &lt;br /&gt;CellPadding=&amp;quot;4&amp;quot; &lt;br /&gt;ForeColor=&amp;quot;#333333&amp;quot; &lt;br /&gt;GridLines=&amp;quot;None&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;HeaderStyle BackColor=&amp;quot;#5D7B9D&amp;quot; Font-Bold=&amp;quot;True&amp;quot; ForeColor=&amp;quot;White&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;RowStyle BackColor=&amp;quot;#F7F6F3&amp;quot; ForeColor=&amp;quot;#333333&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;Columns&amp;gt;&lt;br /&gt;&amp;lt;asp:BoundField DataField=&amp;quot;OrderDate&amp;quot; HeaderText=&amp;quot;Order Date&amp;quot; DataFormatString=&amp;quot;{0:MMM-dd-yyyy}&amp;quot; HtmlEncode=&amp;quot;False&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;asp:BoundField DataField=&amp;quot;ShippedDate&amp;quot; HeaderText=&amp;quot;Shipped Date&amp;quot; DataFormatString=&amp;quot;{0:MMM-dd-yyyy}&amp;quot; HtmlEncode=&amp;quot;False&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;asp:BoundField DataField=&amp;quot;ShipCity&amp;quot; HeaderText=&amp;quot;Shipped To&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/Columns&amp;gt;&lt;br /&gt;&amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;&amp;lt;/Columns&amp;gt;        &lt;br /&gt;&amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;&amp;lt;asp:SqlDataSource ID=&amp;quot;SqlDataSource1&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;ConnectionString=&amp;quot;&amp;lt;%$ ConnectionStrings:NorthWindConnectionString %&amp;gt;&amp;quot;&lt;br /&gt;SelectCommand=&amp;quot;SELECT [CustomerID], [CompanyName], [ContactName], [Address], [City], [PostalCode], [Phone] FROM [Customers]&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/asp:SqlDataSource&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;In ASPX.CS Page&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:c-sharp"&gt;protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)&lt;br /&gt;{&lt;br /&gt;if(e.Row.RowType == DataControlRowType.DataRow)&lt;br /&gt;{&lt;br /&gt;GridView gv = (GridView)e.Row.FindControl("GridView2");&lt;br /&gt;SqlDataSource dbSrc = new SqlDataSource();&lt;br /&gt;dbSrc.ConnectionString = ConfigurationManager.ConnectionStrings["NorthWindConnectionString"].ConnectionString;&lt;br /&gt;dbSrc.SelectCommand = "SELECT * FROM Orders WHERE CustomerID = '" + GridView1.DataKeys[e.Row.RowIndex].Value + "' ORDER BY OrderDate";&lt;br /&gt;gv.DataSource = dbSrc;&lt;br /&gt;gv.DataBind();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Put this JavaScript in the header of your ASPX Page&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:jscript"&gt;function ShowChildGrid(obj)&lt;br /&gt;{&lt;br /&gt;var div = document.getElementById(obj);&lt;br /&gt;var img = document.getElementById('img' + obj);&lt;br /&gt;var theFlag = div.style.display == "none";&lt;br /&gt;div.style.display = (theFlag) ? "inline" : "none";&lt;br /&gt;img.src = (theFlag) ? "Images/arrowdown.jpg" : "Images/arrowright.jpg";&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Happy Coding!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-1160831711615961157?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/1160831711615961157/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2008/07/nested-gridview.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/1160831711615961157'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/1160831711615961157'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2008/07/nested-gridview.html' title='Nested GridView'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp2.blogger.com/_uM-oszK-kVo/SH8v94tymXI/AAAAAAAAAv8/-Hxx5Cmsxjg/s72-c/nestedgridview.JPG' height='72' width='72'/><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-1780877101589510709</id><published>2008-07-17T16:14:00.012+05:30</published><updated>2010-12-01T17:08:29.871+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript Space Trim'/><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript Trim Space'/><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript Strip Spaces'/><category scheme='http://www.blogger.com/atom/ns#' term='Strip Space'/><category scheme='http://www.blogger.com/atom/ns#' term='Remove Spaces'/><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript Trim'/><title type='text'>Trim(Remove Spaces) using JavaScript</title><content type='html'>Here is a simple JS function to trim the outer spaces inside a string.&lt;br /&gt;Mainly used while validating User Inputs.&lt;br /&gt;&lt;br /&gt;These are the three methods that we normally use&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-weight:bold;"&gt;Method 1&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Write a TrimString function using regular expression and call it when needed.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:jscript"&gt;function TrimString(stringToTrim){&lt;br /&gt;    return stringToTrim.replace(/^\s+|\s+$/g,"");&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now call it like &lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:jscript"&gt; var trimmedString = TrimString("    string to be trimmed         ");&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If you alert trimmedString, you will get the value "string to be trimmed"&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-weight:bold;"&gt;OR Method 2&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;If you want a more generic function for trimming, I would suggest taking &lt;a target="_blank" href="http://javascript.crockford.com/remedial.html"&gt;a piece from Douglos Crockfords Remedial Javascript&lt;/a&gt;&lt;br /&gt;Here we are extending the javascript String object with our own trim() function.&lt;br /&gt;This is how we do that.&lt;br /&gt;Declare the following prototype on the top of your page&lt;b&gt; before any call to trim() occurs&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:jscript"&gt;if (!String.prototype.trim) {&lt;br /&gt;    String.prototype.trim = function () {&lt;br /&gt;        return this.replace(/^\s*(\S*(?:\s+\S+)*)\s*$/, "$1");&lt;br /&gt;    };&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now trim the string like&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:jscript"&gt;var str = "    string to be trimmed         ";&lt;br /&gt;var trimmedString = str.trim();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-weight:bold;"&gt;OR Method 3&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;And if you are using jQuery, its much simpler.&lt;br /&gt;jQuery natively has the trim() functionality and so just call it&lt;br /&gt;No points for guessing that though! [:)]&lt;br /&gt;&lt;pre class="brush:jscript"&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;var str = "    string to be trimmed         ";&lt;br /&gt;var trimmedString = jQuery.trim(str);&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-1780877101589510709?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/1780877101589510709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2008/07/trimremove-spaces-using-javascript.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/1780877101589510709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/1780877101589510709'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2008/07/trimremove-spaces-using-javascript.html' title='Trim(Remove Spaces) using JavaScript'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-7163018905944162496</id><published>2008-07-17T15:56:00.006+05:30</published><updated>2009-10-05T17:13:48.264+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Grid Row HyperLink'/><category scheme='http://www.blogger.com/atom/ns#' term='GridViewRow HyperLink'/><category scheme='http://www.blogger.com/atom/ns#' term='Click GridView'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Click Grid'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='ASPX'/><category scheme='http://www.blogger.com/atom/ns#' term='Clickable GridViewRow'/><category scheme='http://www.blogger.com/atom/ns#' term='Click Row'/><title type='text'>GridViewRow as Hyperlink</title><content type='html'>This is a simple technique used in the &lt;span style="font-weight:bold;"&gt;RowDataBound&lt;/span&gt; event of a &lt;span style="font-weight:bold;"&gt;GridView&lt;/span&gt; so that its &lt;span style="font-weight:bold;"&gt;Entire Row acts as a HyperLink&lt;/span&gt;.&lt;br /&gt;For Visual effects styles are applied at &lt;span style="font-weight:bold;"&gt;mouseover and mouseout&lt;/span&gt;.&lt;br /&gt;The cursor is also given a hand like appearance to show the row is a hyperlink&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="csharp"&gt;&lt;br /&gt;protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)&lt;br /&gt;{&lt;br /&gt;    if (e.Row.RowType == DataControlRowType.DataRow)&lt;br /&gt;    {&lt;br /&gt;        e.Row.Attributes["onmouseover"] = "this.style.color='DodgerBlue';this.style.cursor='hand';";&lt;br /&gt;        e.Row.Attributes["onmouseout"] = "this.style.color='Black';";&lt;br /&gt;        e.Row.Attributes["onclick"] = "window.navigate('NavigatedPage.aspx?id=" + e.Row.RowIndex + "')";&lt;br /&gt;        // can send anything as querystring&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-7163018905944162496?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/7163018905944162496/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2008/07/gridviewrow-as-hyperlink.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/7163018905944162496'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/7163018905944162496'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2008/07/gridviewrow-as-hyperlink.html' title='GridViewRow as Hyperlink'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-5044071000562581686</id><published>2008-07-17T12:51:00.011+05:30</published><updated>2010-11-10T14:44:26.014+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='zindex div'/><category scheme='http://www.blogger.com/atom/ns#' term='popup div'/><category scheme='http://www.blogger.com/atom/ns#' term='div over div'/><category scheme='http://www.blogger.com/atom/ns#' term='modal div'/><category scheme='http://www.blogger.com/atom/ns#' term='javascript div'/><title type='text'>Popup Style DIV using Javascript</title><content type='html'>Update at November 10, 2010:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;I am appalled by the numbers of visits this link is getting. Go through it just to understand how its basically done. But I suggest you dont use this code at all :)&lt;/blockquote&gt;&lt;br /&gt;&lt;b&gt;Instead, use Malsup's Wonderful jQuery BlockUI Plugin &lt;/b&gt;: &lt;a href="http://www.malsup.com/jquery/block/#demos"&gt;Demos are here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This sample is to create a pop-up using a DIV in the same page as passing values to and from the pop-up is easier&lt;br /&gt;&lt;br /&gt;The Demo Pics are&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Before Click&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_uM-oszK-kVo/SH774Ch-xvI/AAAAAAAAAvQ/3NIQGxzeooQ/s1600-h/BeforeClick.JPG"&gt;&lt;img style="cursor: pointer;" src="http://bp2.blogger.com/_uM-oszK-kVo/SH774Ch-xvI/AAAAAAAAAvQ/3NIQGxzeooQ/s320/BeforeClick.JPG" alt="" id="BLOGGER_PHOTO_ID_5223889557966997234" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;After Click&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp0.blogger.com/_uM-oszK-kVo/SH78D2ZtH-I/AAAAAAAAAvY/8Zof5pGQw4s/s1600-h/AfterClick.JPG"&gt;&lt;img style="cursor: pointer;" src="http://bp0.blogger.com/_uM-oszK-kVo/SH78D2ZtH-I/AAAAAAAAAvY/8Zof5pGQw4s/s320/AfterClick.JPG" alt="" id="BLOGGER_PHOTO_ID_5223889760869490658" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The CSS.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:css"&gt;.opaqueLayer&lt;br /&gt;{&lt;br /&gt;display:none;&lt;br /&gt;position:absolute;&lt;br /&gt;top:0px;&lt;br /&gt;left:0px;&lt;br /&gt;opacity:0.6;&lt;br /&gt;filter:alpha(opacity=60);&lt;br /&gt;background-color: #000000;&lt;br /&gt;z-Index:1000;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;.questionLayer&lt;br /&gt;{&lt;br /&gt;position:absolute;&lt;br /&gt;top:0px;&lt;br /&gt;left:0px;&lt;br /&gt;width:350px;&lt;br /&gt;height:200px;&lt;br /&gt;display:none;&lt;br /&gt;z-Index:1001;&lt;br /&gt;border:2px solid black;&lt;br /&gt;background-color:#FFFFFF;&lt;br /&gt;text-align:center;&lt;br /&gt;vertical-align:middle;&lt;br /&gt;padding:10px;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The Javascript.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:javascript"&gt;function getBrowserHeight() {&lt;br /&gt;var intH = 0;&lt;br /&gt;var intW = 0;&lt;br /&gt;&lt;br /&gt;if(typeof window.innerWidth == 'number' ) {&lt;br /&gt;intH = window.innerHeight;&lt;br /&gt;intW = window.innerWidth;&lt;br /&gt;}&lt;br /&gt;else if(document.documentElement &amp;&amp; (document.documentElement.clientWidth || document.documentElement.clientHeight)) {&lt;br /&gt;intH = document.documentElement.clientHeight;&lt;br /&gt;intW = document.documentElement.clientWidth;&lt;br /&gt;}&lt;br /&gt;else if(document.body &amp;&amp; (document.body.clientWidth || document.body.clientHeight)) {&lt;br /&gt;intH = document.body.clientHeight;&lt;br /&gt;intW = document.body.clientWidth;&lt;br /&gt;}&lt;br /&gt;return { width: parseInt(intW), height: parseInt(intH) };&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function setLayerPosition() {&lt;br /&gt;var shadow = document.getElementById('shadow');&lt;br /&gt;var question = document.getElementById('question');&lt;br /&gt;&lt;br /&gt;var bws = getBrowserHeight();&lt;br /&gt;shadow.style.width = bws.width + 'px';&lt;br /&gt;shadow.style.height = bws.height + 'px';&lt;br /&gt;question.style.left = parseInt((bws.width - 350) / 2)+ 'px';&lt;br /&gt;question.style.top = parseInt((bws.height - 200) / 2)+ 'px';&lt;br /&gt;shadow = null;&lt;br /&gt;question = null;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function showLayer() {&lt;br /&gt;setLayerPosition();&lt;br /&gt;&lt;br /&gt;var shadow = document.getElementById('shadow');&lt;br /&gt;var question = document.getElementById('question');&lt;br /&gt;&lt;br /&gt;shadow.style.display = 'block';&lt;br /&gt;question.style.display = 'block';&lt;br /&gt;&lt;br /&gt;shadow = null;&lt;br /&gt;question = null;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function hideLayer() {&lt;br /&gt;var shadow = document.getElementById('shadow');&lt;br /&gt;var question = document.getElementById('question');&lt;br /&gt;&lt;br /&gt;shadow.style.display = 'none';&lt;br /&gt;question.style.display = 'none';&lt;br /&gt;&lt;br /&gt;shadow = null;&lt;br /&gt;question = null;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;window.onresize = setLayerPosition;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;And now, the HTML itself&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="bruch:xhtml"&gt;&amp;lt;div id=&amp;quot;shadow&amp;quot; class=&amp;quot;opaqueLayer&amp;quot;&amp;gt; &amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;question&amp;quot; class=&amp;quot;questionLayer&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;br /&amp;gt;&lt;br /&gt;This is the Popup DIV&lt;br /&gt;&amp;lt;br /&amp;gt;&lt;br /&gt;Put anything here, Textbox or Buttons &lt;br /&gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;button&amp;quot; onclick=&amp;quot;hideLayer();&amp;quot; value=&amp;quot;Close&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;table style=&amp;quot;margin-left:auto;margin-right:auto;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&lt;br /&gt;&amp;lt;td style=&amp;quot;height:120px;&amp;quot;&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&lt;br /&gt;&amp;lt;td&amp;gt;&lt;br /&gt;&amp;lt;button onclick=&amp;quot;showLayer();&amp;quot;&amp;gt;Click Me to see the Popup DIV&amp;lt;/button&amp;gt;&lt;br /&gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Explanation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here two other DIVS are placed in the page which are hidden at first.&lt;br /&gt;When clicking on the Button they are rendered visible.&lt;br /&gt;These two DIVs are having different &lt;a href="http://www.google.com/search?aq=f&amp;amp;complete=1&amp;amp;hl=en&amp;amp;q=z-index&amp;amp;btnG=Search"&gt;Z-Indexes&lt;/a&gt; that makes them look like a Popup Window.&lt;br /&gt;&lt;br /&gt;Happy Coding!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-5044071000562581686?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/5044071000562581686/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2008/07/popup-style-div-using-javascript.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/5044071000562581686'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/5044071000562581686'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2008/07/popup-style-div-using-javascript.html' title='Popup Style DIV using Javascript'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp2.blogger.com/_uM-oszK-kVo/SH774Ch-xvI/AAAAAAAAAvQ/3NIQGxzeooQ/s72-c/BeforeClick.JPG' height='72' width='72'/><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777933054050893742.post-6297142246628924898</id><published>2008-05-30T12:22:00.002+05:30</published><updated>2009-03-25T11:06:20.634+05:30</updated><title type='text'>Cant Set  "Show Hidden Files" aka  Removing AMVO.EXE</title><content type='html'>Beware when Plugging USBs to another System.&lt;br /&gt;You will get a nasty amvo.exe!&lt;br /&gt;&lt;br /&gt;First I got a memory reference error as alert.&lt;br /&gt;I didn't mind it then, why bother with a silly alert?&lt;br /&gt;&lt;br /&gt;After few days I noticed problems like&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Cannot set "show hidden files and folders" inside the Tools--&gt;Folder Options--&gt;View&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Contaminating every USBs plugged into it.&lt;/li&gt;&lt;/ul&gt;As most of us do, I googled it.&lt;br /&gt;They asked me to check whether amvo.exe is the culprit.&lt;br /&gt;&lt;br /&gt;To check that I &lt;span style="font-weight: bold;"&gt;Run&lt;/span&gt; &lt;i style="font-weight: bold;"&gt;msconfig&lt;/i&gt;. In the "&lt;span style="font-weight: bold;"&gt;Startup&lt;/span&gt;" Tab I found &lt;span style="font-weight: bold;"&gt;amvo.exe&lt;/span&gt; (&lt;a href="http://www.prevx.com/filenames/1360796256778365074-X1/AMVO.EXE.html"&gt;Details&lt;/a&gt;)&lt;br /&gt;Bingo! Got the virus/malware!&lt;br /&gt;&lt;br /&gt;Now how to remove it?&lt;br /&gt;&lt;br /&gt;Again I googled it. (What will be life without Google?) [:)]&lt;br /&gt;Saw some options at &lt;span style="font-weight: bold;"&gt;the Digital me&lt;/span&gt; 's &lt;a href="http://digitalpbk.blogspot.com/2008/02/amvoexe-virus-usb-memory-stick.html"&gt;Blog&lt;/a&gt;.&lt;br /&gt;Since it was based on manipulations on &lt;span style="font-weight: bold;"&gt;Windows Registry&lt;/span&gt;, I opted not to go for it.&lt;br /&gt;Was totally at sea, on what to do next.&lt;br /&gt;Then I started reading Comments for the topic at &lt;span style="font-weight: bold;"&gt;the Digital me &lt;/span&gt;'s blog.&lt;br /&gt;I came across a splendid method by &lt;a href="http://digitalpbk.blogspot.com/2008/02/amvoexe-virus-usb-memory-stick.html#comment-5642631841999595523"&gt;Olalekan&lt;/a&gt;&lt;br /&gt;Based on that some steps were formulated.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Login inside Windows as Administrator or with Administrator previleges.&lt;br /&gt;&lt;br /&gt;Run &lt;span style="font-weight: bold;"&gt;cmd (&lt;/span&gt;Opens DOS Window&lt;span style="font-weight: bold;"&gt;)&lt;/span&gt;&lt;br /&gt;Now type &lt;span style="font-weight: bold;"&gt;C:&lt;/span&gt; to get to the C Prompt  inside the  DOS&lt;br /&gt;Type: &lt;span style="font-weight: bold;"&gt;taskkill /im explorer.exe /f &lt;/span&gt;  (Ends the Process "Explorer.exe". Important since virus spreads through Explorer)&lt;br /&gt;Type: &lt;span style="font-weight: bold;"&gt;cd %systemroot%\system32&lt;/span&gt;  (Accessing System32)&lt;br /&gt;Type:&lt;span style="font-weight: bold;"&gt; del amvo* /f /q /as&lt;/span&gt; (Deleting every  file starting with  amvo)&lt;br /&gt;Type: &lt;span style="font-weight: bold;"&gt;cd \ &lt;/span&gt;(Going to Root Directory)&lt;br /&gt;Type: &lt;span style="font-weight: bold;"&gt;dir /ah&lt;/span&gt; (List Hidden Files)&lt;br /&gt;&lt;br /&gt;Now the Virus will be listed as"blahblah.com".We should delete it.&lt;br /&gt;Note: &lt;span style="font-weight: bold;"&gt;The virus can never use NTDETECT.com (&lt;/span&gt; Deleting it will cause big time troubles for you)&lt;br /&gt;Now delete the virus using&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;del blahblah.com autorun.inf /f /q /as&lt;/span&gt; (My amvo used something like "iw1eg.com")&lt;br /&gt;&lt;br /&gt;The virus is disposed from C:/ .&lt;/blockquote&gt; &lt;br /&gt;Now its the turn of other drives.&lt;br /&gt;&lt;br /&gt;Suppose you have C:/, D:/, E:/ in your system. Repeat these processes for each drive.&lt;br /&gt;ie. inside cmd type: D:&lt;br /&gt;Now we have reached D: prompt, repeat the steps mentioned above for it too.&lt;br /&gt;Do the same for E:/ and F:/ (if there is one)&lt;br /&gt;&lt;br /&gt;After deleting from all these drives, restart the explorer by typing "explorer.exe"&lt;br /&gt;&lt;br /&gt;Now  the prevention from future attacks&lt;br /&gt;&lt;br /&gt;Disabling AutoPlay  for all drives&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-weight: bold;"&gt;Start &gt; Run &gt; gpedit.msc&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Inside it go to --&gt; Computer Configuration &gt; Administrative Templates &gt; System &gt; Turn Off Autoplay --&gt; Enable&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Now if you wanna View hidden Files a small Change in Registry is required.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-weight: bold;"&gt;Start &gt; Run &gt; &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;regedit&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Inside it Set&lt;br /&gt;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\&lt;br /&gt;Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\SHOWALL&lt;br /&gt;CheckedValue as 1&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Thats all to it Guys! [:)]&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777933054050893742-6297142246628924898?l=blog.codovations.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.codovations.com/feeds/6297142246628924898/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.codovations.com/2008/05/cant-set-show-hidden-files-aka-removing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/6297142246628924898'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777933054050893742/posts/default/6297142246628924898'/><link rel='alternate' type='text/html' href='http://blog.codovations.com/2008/05/cant-set-show-hidden-files-aka-removing.html' title='Cant Set  &quot;Show Hidden Files&quot; aka  Removing AMVO.EXE'/><author><name>Naveen</name><uri>http://www.blogger.com/profile/18157353195373364087</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_uM-oszK-kVo/SmNKa4I8vHI/AAAAAAAACS0/0-yrsPSVSlA/S220/naveenj.jpg'/></author><thr:total>0</thr:total></entry></feed>
