<?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-6886163520614083306</id><updated>2011-04-21T20:55:13.219-07:00</updated><title type='text'>ASP.NET Addicted...</title><subtitle type='html'>This blog is all about my experiences during my various projects mainly concerning with ASP.NET, C#, JQuery, Javascript.Its all about sharing and spreading what you learn, innovate and in turn learn more.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://amin-sayed.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6886163520614083306/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://amin-sayed.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Amin Sayed</name><uri>http://www.blogger.com/profile/17445738924843440757</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://1.bp.blogspot.com/_pFRljW2NHQY/SYq0I32tTjI/AAAAAAAAAlQ/GDbZXrMGzqc/S220/260120091430.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6886163520614083306.post-2503911328748512626</id><published>2008-10-28T02:16:00.000-07:00</published><updated>2009-02-11T01:13:14.443-08:00</updated><title type='text'>Export DataTable into PDF with ASP.NET and iTextSharp.DLL</title><content type='html'>&lt;span style="font-family:georgia;"&gt;In this article I'll demonstrate how to export your DataTable to PDF file format.&lt;br /&gt;&lt;br /&gt;Sometimes it may be the case that you need to export your search result(in tabular format) to a specified file format like .xls, .doc or even .txt. Converting your data to these file format is quite easy and ASP.NET can build it for you internally without letting you worry about any other things.&lt;br /&gt;&lt;br /&gt;However, to export your records to .pdf(Adobe's Portable Digital Format) you need to include some third party tool. In the below case i have used " itextSharp.dll " (DLL) component. Which can be downloded from the SourceForge web-site (&lt;/span&gt;&lt;a style="FONT-FAMILY: arial" href="http://sourceforge.net"&gt;&lt;span style="font-family:georgia;"&gt;http://&lt;/span&gt;&lt;/a&gt;&lt;a style="FONT-FAMILY: arial" href="http://sourceforge.net"&gt;&lt;cite&gt;&lt;span style="font-family:georgia;"&gt;&lt;b&gt;sourceforge&lt;/b&gt;.net&lt;/span&gt;&lt;/cite&gt;&lt;/a&gt;&lt;span style="font-family:georgia;"&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-family:georgia;"&gt;).&lt;br /&gt;&lt;br /&gt;The following function takes a DataTable as a parameter and converts the data present in it into a PDF File Format in a same tabular view.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; iTextSharp.text;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; iTextSharp.text.pdf;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; GeneratePDF(DataTable dataTable)&lt;br /&gt;{&lt;br /&gt;Document pdfDoc = &lt;span class="kwrd"&gt;new&lt;/span&gt; Document(PageSize.A4, 30, 30, 40, 25);&lt;br /&gt;System.IO.MemoryStream mStream = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.IO.MemoryStream();&lt;br /&gt;PdfWriter writer = PdfWriter.GetInstance(pdfDoc, mStream);&lt;br /&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; cols = dataTable.Columns.Count;&lt;br /&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; rows = dataTable.Rows.Count;&lt;br /&gt;pdfDoc.Open();&lt;br /&gt;&lt;br /&gt;iTextSharp.text.Table pdfTable = &lt;span class="kwrd"&gt;new&lt;/span&gt; iTextSharp.text.Table(cols, rows);&lt;br /&gt;pdfTable.BorderWidth = 1;&lt;br /&gt;pdfTable.Width = 100;&lt;br /&gt;pdfTable.Padding = 1;&lt;br /&gt;pdfTable.Spacing = 1;&lt;br /&gt;&lt;br /&gt;    &lt;span class="rem"&gt;//creating table headers&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; cols; i++)&lt;br /&gt;{&lt;br /&gt;   Cell cellCols = &lt;span class="kwrd"&gt;new&lt;/span&gt; Cell();&lt;br /&gt;   Font ColFont = FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.BOLD);&lt;br /&gt;   Chunk chunkCols = &lt;span class="kwrd"&gt;new&lt;/span&gt; Chunk(dataTable.Columns[i].ColumnName, ColFont);&lt;br /&gt;   cellCols.Add(chunkCols);&lt;br /&gt;   pdfTable.AddCell(cellCols);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;    &lt;span class="rem"&gt;//creating table data (actual result)&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; k = 0; k &amp;lt; rows; k++)&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; j = 0; j &amp;lt; cols; j++)&lt;br /&gt;    {&lt;br /&gt;      Cell cellRows = &lt;span class="kwrd"&gt;new&lt;/span&gt; Cell();&lt;br /&gt;      Font RowFont = FontFactory.GetFont(FontFactory.HELVETICA, 12);&lt;br /&gt;      Chunk chunkRows = &lt;span class="kwrd"&gt;new&lt;/span&gt; Chunk(dataTable.Rows[k][j].ToString(), RowFont);&lt;br /&gt;      cellRows.Add(chunkRows);&lt;br /&gt;      pdfTable.AddCell(cellRows);&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;pdfDoc.Add(pdfTable);&lt;br /&gt;pdfDoc.Close();&lt;br /&gt;Response.ContentType = &lt;span class="str"&gt;"application/octet-stream"&lt;/span&gt;;&lt;br /&gt;Response.AddHeader(&lt;span class="str"&gt;"Content-Disposition"&lt;/span&gt;, &lt;span class="str"&gt;"attachment; filename=Report.pdf"&lt;/span&gt;);&lt;br /&gt;Response.Clear();&lt;br /&gt;Response.BinaryWrite(mStream.ToArray());&lt;br /&gt;Response.End();&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;span style="font-size:85%;"&gt;The above function is dynamic and can accept DataTable of any number of rows and columns.&lt;br /&gt;Please note that "Table" class of DLL "itextSharp" namespace is conflicting with the .NET namespace "Web.UI.HtmlControls". Everything else is fine. That's why i used the complete name of this class.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6886163520614083306-2503911328748512626?l=amin-sayed.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://amin-sayed.blogspot.com/feeds/2503911328748512626/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6886163520614083306&amp;postID=2503911328748512626' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6886163520614083306/posts/default/2503911328748512626'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6886163520614083306/posts/default/2503911328748512626'/><link rel='alternate' type='text/html' href='http://amin-sayed.blogspot.com/2008/10/in-this-article-ill-demonstrate-how-to.html' title='Export DataTable into PDF with ASP.NET and iTextSharp.DLL'/><author><name>Amin Sayed</name><uri>http://www.blogger.com/profile/17445738924843440757</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://1.bp.blogspot.com/_pFRljW2NHQY/SYq0I32tTjI/AAAAAAAAAlQ/GDbZXrMGzqc/S220/260120091430.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6886163520614083306.post-9090626581307007590</id><published>2008-10-26T07:05:00.001-07:00</published><updated>2008-12-29T23:59:47.664-08:00</updated><title type='text'>ASP.NET Ajax Request/Response using JQuery</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;Filling ASP.NET DropDown List using jQuery AJAX.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;In this example, i'll demonstrate how to implement AJAX functionality on asp:DropDown change event, and to fill the other Dropdown list &lt;/span&gt;&lt;b&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;without using the ScriptManager class&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; (that comes with ASP.NET AJAX Toolkit)&lt;br /&gt;&lt;br /&gt;For this case, I'm using a Javascript Library called &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;j&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;Query&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;. This must be downloaded and included before using the below source code. (&lt;/span&gt;&lt;a href="http://jquery.com/"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;http://jquery.com&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;)&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;My form contains two DropDowns: &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;Categories(ddlCategories)&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; and &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;Items(ddlItems).&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; OnChange of the Category DropDown I will fill the Items DropDown.&lt;/span&gt;&lt;/div&gt;&lt;pre class="csharpcode"&gt;&amp;lt;form id=&lt;span class="str"&gt;"form1"&lt;/span&gt; runat=&lt;span class="str"&gt;"server"&lt;/span&gt;&amp;gt;&lt;br /&gt;      &amp;lt;asp:DropDownList ID=&lt;span class="str"&gt;"ddlCategories"&lt;/span&gt; runat=&lt;span class="str"&gt;"server"&lt;/span&gt;&amp;gt;&lt;br /&gt;          &amp;lt;asp:ListItem&amp;gt;Select&amp;lt;/asp:ListItem&amp;gt;&lt;br /&gt;          &amp;lt;asp:ListItem&amp;gt;Fruits&amp;lt;/asp:ListItem&amp;gt;&lt;br /&gt;          &amp;lt;asp:ListItem&amp;gt;Vegetables&amp;lt;/asp:ListItem&amp;gt;&lt;br /&gt;          &amp;lt;asp:ListItem&amp;gt;Desserts&amp;lt;/asp:ListItem&amp;gt;&lt;br /&gt;      &amp;lt;/asp:DropDownList&amp;gt;&lt;br /&gt;      &amp;lt;br /&amp;gt;&lt;br /&gt;      &amp;lt;asp:DropDownList ID=&lt;span class="str"&gt;"ddlItems"&lt;/span&gt; runat=&lt;span class="str"&gt;"server"&lt;/span&gt;&amp;gt;&amp;lt;/asp:DropDownList&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;/pre&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;    Here is my ASP.NET Desing View of the Form which shows these DropDowns. I have hardcoded the first DropDown with Categories: Fruits, Vegetables and Desserts. The Items DropDown is empty initially, since we will fill these through jQuery AJAX, when the &lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;onChange&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;event of the Category DropDown will be fired.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;    The Best thing is that we do not have to register any JavaScript Event with any control using our code behind file &lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0); "&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;[ddlCategories.Attributes.Add()]&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;,  jQuery has the functionality where we can write our own &lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;onChange&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; Event function. So here is my jQuery Code in which I will write the &lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;onChange&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; function of the Categories DropDownList and call a C# function (or implement my AJAX) and then finally fill the Items DropDown.&lt;/span&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;&amp;lt;script type=&lt;span class="str"&gt;"text/javascript"&lt;/span&gt; src=&lt;span class="str"&gt;"jquery.js"&lt;/span&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;script type=&lt;span class="str"&gt;"text/javascript"&lt;/span&gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;$(document).ready(function(){&lt;br /&gt;&lt;br /&gt;$(&lt;span class="str"&gt;"#&amp;lt;%=ddlCategories.ClientID %&amp;gt;"&lt;/span&gt;).change(&lt;br /&gt;  function()&lt;br /&gt;  {&lt;br /&gt;    var category = &lt;span class="kwrd"&gt;this&lt;/span&gt;.options[&lt;span class="kwrd"&gt;this&lt;/span&gt;.selectedIndex].&lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;br /&gt;    var ddlItems = document.getElementById(&lt;span class="str"&gt;"&amp;lt;%=ddlItems.ClientID%&amp;gt;"&lt;/span&gt;);&lt;br /&gt;    ddlItems.options.length = 0;&lt;br /&gt;    $.ajax&lt;br /&gt;    ({&lt;br /&gt;             type: &lt;span class="str"&gt;"POST"&lt;/span&gt;,&lt;br /&gt;             contentType: &lt;span class="str"&gt;"application/json; charset=utf-8"&lt;/span&gt;,&lt;br /&gt;             url: &lt;span class="str"&gt;"Default.aspx/getItems"&lt;/span&gt;,&lt;br /&gt;             data: &lt;span class="str"&gt;"{'category':'"&lt;/span&gt;+category+&lt;span class="str"&gt;"'}"&lt;/span&gt;,&lt;br /&gt;             dataType: &lt;span class="str"&gt;"json"&lt;/span&gt;,&lt;br /&gt;             success: function(msg)&lt;br /&gt;             {&lt;br /&gt;                  var arrItems = msg.d.split(&lt;span class="str"&gt;"|"&lt;/span&gt;);&lt;br /&gt;                  &lt;span class="kwrd"&gt;for&lt;/span&gt;(var i=0; i&amp;lt; arrItems.length; i++)&lt;br /&gt;                  {&lt;br /&gt;                     var opt = document.createElement(&lt;span class="str"&gt;"option"&lt;/span&gt;);&lt;br /&gt;                     ddlItems.options.add(opt)&lt;br /&gt;                     opt.text = arrItems[i];&lt;br /&gt;                     opt.&lt;span class="kwrd"&gt;value&lt;/span&gt; = arrItems[i];&lt;br /&gt;                  }&lt;br /&gt;             }&lt;br /&gt;     });&lt;br /&gt; }&lt;br /&gt;);&lt;br /&gt;});&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;Any jQuery implementation should be inside $(document).ready() function. This is the root function that is called everytime any event occurs on our page. In the above code we have written our &lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;onChange &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;function inside this [ &lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 102, 0);"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;as $("#ddlCategories").change() &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;]. Inside this function we are catching up the item that is selected. The actual request for a C# function or AJAX function can be done through jQuery's $.ajax() function. This function takes 6 parameters that can be explained as follows:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;1. &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;type: &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;this is the Request type that we are going to make. Normally it is of type post.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;2. &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;contenType: &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;ASP.NET AJAX script services and page methods understand and expect parameters serialized as JSON strings. These parameters are parsed out of the POST data and used as arguments to the method you’ve called.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;3.  url: &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;This contains the url of the page that will handle our AJAX request and provide the response. Notice here we have defined our url as &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;Default.aspx/getItems. &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;The first element before slash(/) contains the page name and the second item is the actual function name that will process the request in this case its &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;getItems. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;4. data: &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;This option defines the parameters that have to be passed (if any) to the function on the basis of which our request will be processed. In this case we are passing the selected value of the Category dropDown. Also its worth noting that the parameter name of this option should match the parameter of the function that we are going to call. In this case its &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;'category'&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;. &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;5. &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;dataType: &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;this option defines the type of Data that will be returned to us when the request is processed successfully. In this case its JSON (JavaScript Object Notation).&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;6.&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;success: &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;this option is an indication of a successful request processed and response. In this function we will define a function that will process the response (i.e. fill the Items dropDown). As you'll look at the C# code below, we are appending the items using a bar( | ), coz if there are multiple items we need to handle them in response. Here we are finally splitting the response string and finally handling each of them separately by storing them in the Items DropDown list.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;Finally here is the C# Code Behind function that will handle my Request, Process it and Response back the output. Currently I have hard coded mr response. We can also make a database request and finally append each of the items using a bar ( | ) and response back the string (output).&lt;/span&gt;&lt;/div&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; _Default : System.Web.UI.Page&lt;br /&gt;{&lt;br /&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Page_Load(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;[System.Web.Services.WebMethod]&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; getItems(&lt;span class="kwrd"&gt;string&lt;/span&gt; category)&lt;br /&gt;{&lt;br /&gt;  &lt;span class="kwrd"&gt;string&lt;/span&gt; strItems = &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;  &lt;span class="kwrd"&gt;if&lt;/span&gt; (category == &lt;span class="str"&gt;"Fruits"&lt;/span&gt;)&lt;br /&gt;  {&lt;br /&gt;      strItems = &lt;span class="str"&gt;"Apple|Orange|Pinapple|Grapes"&lt;/span&gt;;&lt;br /&gt;  }&lt;br /&gt;  &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (category == &lt;span class="str"&gt;"Vegetables"&lt;/span&gt;)&lt;br /&gt;  {&lt;br /&gt;      strItems = &lt;span class="str"&gt;"Tomato|Cauliflower|Brinjal|Potato"&lt;/span&gt;;&lt;br /&gt;  }&lt;br /&gt;  &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (category == &lt;span class="str"&gt;"Desserts"&lt;/span&gt;)&lt;br /&gt;  {&lt;br /&gt;      strItems = &lt;span class="str"&gt;"Cakes|Cookies|IceCreams|Pastries"&lt;/span&gt;;&lt;br /&gt;  }&lt;br /&gt;  &lt;span class="kwrd"&gt;return&lt;/span&gt; strItems;&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/6886163520614083306-9090626581307007590?l=amin-sayed.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://amin-sayed.blogspot.com/feeds/9090626581307007590/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6886163520614083306&amp;postID=9090626581307007590' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6886163520614083306/posts/default/9090626581307007590'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6886163520614083306/posts/default/9090626581307007590'/><link rel='alternate' type='text/html' href='http://amin-sayed.blogspot.com/2008/10/in-this-example-ill-demonstrate-how-to.html' title='ASP.NET Ajax Request/Response using JQuery'/><author><name>Amin Sayed</name><uri>http://www.blogger.com/profile/17445738924843440757</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://1.bp.blogspot.com/_pFRljW2NHQY/SYq0I32tTjI/AAAAAAAAAlQ/GDbZXrMGzqc/S220/260120091430.jpg'/></author><thr:total>2</thr:total></entry></feed>
