<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>AjaxZen</title>
	<atom:link href="http://ajaxzen.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ajaxzen.wordpress.com</link>
	<description>{ asp.net mvc, ajax, .net, javascript and more... }</description>
	<lastBuildDate>Thu, 04 Dec 2008 16:33:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ajaxzen.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>AjaxZen</title>
		<link>http://ajaxzen.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ajaxzen.wordpress.com/osd.xml" title="AjaxZen" />
	<atom:link rel='hub' href='http://ajaxzen.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Ajax in Asp.net</title>
		<link>http://ajaxzen.wordpress.com/2008/12/03/ajax-in-aspnet/</link>
		<comments>http://ajaxzen.wordpress.com/2008/12/03/ajax-in-aspnet/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 19:13:37 +0000</pubDate>
		<dc:creator>writer007</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[GetCallbackEventReference]]></category>
		<category><![CDATA[ICallbackEventHandler]]></category>
		<category><![CDATA[JAVASCRIPT]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET AJAX]]></category>

		<guid isPermaLink="false">http://ajaxzen.wordpress.com/?p=93</guid>
		<description><![CDATA[In today&#8217;s blog entry, I&#8217;m going to take a step back from MVC Frame Work and write little bit about Asp.net. We will be focusing on how to make an Ajax call within Asp.net Web Forms. Many programmers had asked me about implementing Ajax in Asp.net Web Forms. This will give me an opportunity to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxzen.wordpress.com&amp;blog=5656764&amp;post=93&amp;subd=ajaxzen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div style="font-family:verdana;font-size:11px;font-weight:bold;color:black;">
In today&#8217;s blog entry, I&#8217;m going to take a step back from MVC Frame Work and write little bit about Asp.net. We will be focusing on how to make an Ajax call within Asp.net Web Forms. Many programmers had asked me about implementing Ajax in Asp.net Web Forms. This will give me an opportunity to respond to that and besides I get a chance to take a short break from our MVC series. </p>
<p>What we need to get started?</p>
<ul>
<li>Visual Studio 2005 or higher</li>
<li> .NET Frame Work 2.0 or higher</li>
<li>ICallbackEventHandler :- Interface which is part of the System.Web.UI</li>
<li>RaiseCallbackEvent :- Method part of the ICallbackEventHandler that when invoked will communicate with the server.</li>
<li>GetCallbackResult :- This method is also part of the ICallbackEventHandler interface that will return results to the client.</li>
</ul>
<p>Also, we need little bit of JavaScript which we will register onto the page from server side. </p>
<ul>
<li>First function :- Makes that actual request to the server.</li>
<li>Second function :- Handles an error that come up during the call.</li>
<li>Final function :- This is that main function that will be responsible for making the Ajax call. Also, it will be automatically generated by Asp.net. You will see in a sec. </li>
</ul>
<p>Here is the code of the Page_Load event :-
</p></div>
<p><pre class="brush: csharp;">
protected void Page_Load(object sender, EventArgs e)
{
     #region Generic ajax call script registration 
     string js = Page.ClientScript.GetCallbackEventReference(this, &quot;arg&quot;, &quot;OnReturnedData&quot;,
            &quot;ctx&quot;, &quot;OnError&quot;, true);

     //create a simplified wrapper method
     StringBuilder newFunc = new StringBuilder();
     newFunc.Append(&quot;function StartAsyncCall(arg, ctx) &quot;);
     newFunc.Append(&quot;{ &quot;); 
     newFunc.Append(js);
     newFunc.Append(&quot; } &quot;);

     //register it
    Page.ClientScript.RegisterClientScriptBlock(typeof(Test), &quot;AsyncMethod&quot;,
                       newFunc.ToString(), true);
     #endregion
}

</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;color:black;">
Couple of things are happening here, which are quite simple as you will soon see:-</p>
<p>1. Page.ClientScript.GetCallbackEventReference(control, argument, clientCallback, context, async)</p>
<ul>
<li>control :- Server control that handles the client callback. This control must also implement ICallbackEventHandler interface &amp; provide a RaiseCallbackEvent method. In our case, it&#8217;s the page itself.</li>
<li>argument :- Arguments passed from the element script to the server.</li>
<li>clientCallback :- The name of the client event handler that receives the result.</li>
<li>context :- Client script is evaluated on the client prior to initiating callback. The result of the script  is passed back to the client event handler.</li>
<li>clientError :- Client event handler that handles the error.</li>
<li>useAsync :- Set true to perform callback asynchronously, false for synchronously.</li>
</ul>
<p>2. Function StartAsyncCall will be regenerated automatically which we will call within our custom JavaScript function. </p>
<p>3. The last line, simply registers our JavaScript on to the page.<br />
 Page.ClientScript.RegisterClientScriptBlock(typeof script, key, script string, add script tag);</p>
<p>Now, we got that over with, it is time to inherit from ICallBackEventHandler.</p>
<p>complete c# code of our Test.aspx.cs page:-
</p></div>
<p><pre class="brush: csharp;">
 public partial class Test : Page, ICallbackEventHandler
{
    public string retVal = string.Empty; //global variable that will store our return value
    protected void Page_Load(object sender, EventArgs e)
    {
        #region Generic ajax call script registration
        
        string js = Page.ClientScript.GetCallbackEventReference(this, &quot;arg&quot;, &quot;OnReturnedData&quot;,
                &quot;ctx&quot;, &quot;OnError&quot;, true);

        //create a simplified wrapper method
        StringBuilder newFunc = new StringBuilder();
        newFunc.Append(&quot;function StartAsyncCall(arg, ctx) &quot;);
        newFunc.Append(&quot;{ &quot;);
        newFunc.Append(js);
        newFunc.Append(&quot; } &quot;);

        //register it
        Page.ClientScript.RegisterClientScriptBlock(typeof(Test), &quot;AsyncMethod&quot;,
                            newFunc.ToString(), true);

        #endregion
    }

    #region implement ICallbackEventHandler Members
    public string GetCallbackResult()
    {
        //return value back to client side
        return retVal;
    }

    public void  RaiseCallbackEvent(string eventArgument)
    {
        //do the server side process here....
        retVal = eventArgument;
    }
    #endregion
}
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;color:black;">
Simple enough for you&#8230;</p>
<p>Complete HTML code for our Test.aspx:-
</p></div>
<p><pre class="brush: xml;">
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;
&lt;head id=&quot;Head1&quot; runat=&quot;server&quot;&gt;
    &lt;title&gt;Untitled Page&lt;/title&gt;
    &lt;script language=&quot;javascript&quot;&gt;
       
       //Global variable for our container div
        var objContainer = null;
       
        //Our custom javascript function that will be invoked by some kind of event.
       //In our case, AjaxTest() is being invoked by the onclick event.
        function AjaxTest()
        {
            //user input
            var objInput = document.getElementById(&quot;txtInput&quot;);
            
            //get container element 
            objContainer = document.getElementById(&quot;container&quot;);
            
            //dispaly a loading message in the container before the call...
            objContainer.innerHTML = &quot;loading....&quot;;
            
            //call the autogenerated ajax call function.
            StartAsyncCall(objInput.value);
        }

        //When everything goes well, OnReturnedData function will -
        //handle our returned data.
        function OnReturnedData(arg, ctx)
        {          
            //clear the content of the container
            objContainer.innerHTML = &quot;&quot;;

            //than display the return data from the server.
            objContainer.innerHTML = &quot;Respond from server:- Hi! &quot; + arg;            
        }

        //When things go wrong OnError() function will come in handy...
        function OnError(err, ctx)
        {
            //display error message in our container
            objContainer.innerHTML = err; 
        }

    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
    Type your name to talk to the server:
    &lt;input id=&quot;txtInput&quot; name=&quot;txtInput&quot; type=&quot;text&quot; size=&quot;40px&quot; /&gt;
    &lt;a href=&quot;#&quot; onclick=&quot;AjaxTest();&quot;&gt;Submit Name&lt;/a&gt;
 &lt;div id=&quot;container&quot; style=&quot;color: Red;&quot;&gt;&lt;/div&gt;
 &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;color:black;">
Here is what the final output would look like:-<br />
<img src="http://ajaxzen.files.wordpress.com/2008/12/aspnetfinaloutput.png?w=460&#038;h=105" alt="aspnetfinaloutput" title="aspnetfinaloutput" width="460" height="105" class="alignnone size-full wp-image-102" /><br />
Look!!! maa, No page refresh&#8230;.</p>
<p>I hope this blog entry will help you to add creativity to your web application.
</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajaxzen.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajaxzen.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajaxzen.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajaxzen.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajaxzen.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajaxzen.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajaxzen.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajaxzen.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajaxzen.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajaxzen.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajaxzen.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajaxzen.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajaxzen.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajaxzen.wordpress.com/93/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxzen.wordpress.com&amp;blog=5656764&amp;post=93&amp;subd=ajaxzen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajaxzen.wordpress.com/2008/12/03/ajax-in-aspnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/031ed086889313e3f5e928c8f9599cf9?s=96&#38;d=identicon" medium="image">
			<media:title type="html">writer007</media:title>
		</media:content>

		<media:content url="http://ajaxzen.files.wordpress.com/2008/12/aspnetfinaloutput.png" medium="image">
			<media:title type="html">aspnetfinaloutput</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET MVC GRID part 2</title>
		<link>http://ajaxzen.wordpress.com/2008/11/30/aspnet-mvc-grid-part-2/</link>
		<comments>http://ajaxzen.wordpress.com/2008/11/30/aspnet-mvc-grid-part-2/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 23:17:20 +0000</pubDate>
		<dc:creator>writer007</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET MVC GRID]]></category>
		<category><![CDATA[GRD]]></category>
		<category><![CDATA[JAVASCRIPT]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[GRID]]></category>
		<category><![CDATA[JQUERY]]></category>

		<guid isPermaLink="false">http://ajaxzen.wordpress.com/?p=50</guid>
		<description><![CDATA[Welcome back, we&#8217;ll pick up where we left off. If you haven&#8217;t gotten a chance to read the Part I of this series. Please do so now. We will be expanding our project that we had started in Part I in today&#8217;s article. We&#8217;ll began by modifying our Index.aspx View by adding a hyperlink and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxzen.wordpress.com&amp;blog=5656764&amp;post=50&amp;subd=ajaxzen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div style="font-family:verdana;font-size:11px;font-weight:bold;">Welcome back, we&#8217;ll pick up where we left off. If you haven&#8217;t gotten a chance to read the <a href="http://ajaxzen.wordpress.com/2008/11/27/aspnet-mvc-grid-part-1/">Part I</a> of this series. Please do so now.</p>
<p>We will be expanding our project that we had started in <a href="http://ajaxzen.wordpress.com/2008/11/27/aspnet-mvc-grid-part-1/">Part I</a> in today&#8217;s article. We&#8217;ll began by modifying our Index.aspx View by adding a hyperlink and a place holder div, which we will use to render our Grid.
</div>
<p><pre class="brush: xml;">
&lt;a href=&quot;#&quot; onclick=&quot;AjaxCall();&quot;&gt;Make Ajax call&lt;/a&gt;
&lt;div id=&quot;GridContent&quot;&gt;&lt;/div&gt;
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
I used the standard hyperlink tag because I find it way less complicated to implement. You don&#8217;t have to take my words for it, see it for yourself.</p>
<p>If was to create a hyperlink using the ASP.NET MVC Html helper. It would look like this:
</p></div>
<p><pre class="brush: xml;">
&lt;%= Html.ActionLink(&quot;link test&quot;, &quot;GetAjaxGrid&quot;) %&gt;  </pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
to add attributes I would need to pass a dictionary object:
</div>
<p><pre class="brush: xml;">
&lt;% IDictionary&lt;String, String&gt; linkAttr = new Dictionary&lt;String, String&gt;();
linkAttr.Add(&quot;onclick&quot;, &quot;AjaxCall();&quot;); %&gt;
&lt;%= Html.ActionLink(&quot;link test&quot;, &quot;GetAjaxGrid&quot;, null, linkAttr) %&gt;
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
Second thing, we need to do is to modify our Home Controller . We&#8217;ll create a new action called GetAjaxGrid that will handle our Ajax request.
</div>
<p><pre class="brush: csharp;">
public ContentResult GetAjaxGrid()
{
       //var type is the implicit variable type declartion.
         var model = new MVCGridModel();

         return Content(model.GetResults());
}
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
If you remember back in <a href="http://ajaxzen.wordpress.com/2008/11/27/aspnet-mvc-grid-part-1/">part I</a>, ContentResult is part of the six action types that the Controller returns. Since, we are not returning a View, we just need to return the HTML markup. ContentResult seems to be the best option in this situation. We could have instead create a void action that will return our string content via Response.Write().</p>
<p>Yep, it is possible to use Response.Write() within the Controller and will behave like a JavaScript alert() function.
</p></div>
<p><pre class="brush: csharp;">
public void GetAjaxGrid()
{
       //var type is the implicit variable type declartion.
         var model = new MVCGridModel();
         Response.Write(model.GetResults());
}
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
I had successfully used the latter method in many of my real world applications and works well.</p>
<p>Next thing we need to do is create a JavaScript file. This will help us to keep things organized.</p>
<p style="padding-left:30px;"><a href="http://ajaxzen.files.wordpress.com/2008/11/scriptfolder1.png"><img class="alignnone size-full wp-image-51" title="scriptfolder1" src="http://ajaxzen.files.wordpress.com/2008/11/scriptfolder1.png?w=172&#038;h=65" alt="scriptfolder1" width="172" height="65" /></a></p>
<p>Create a new function called AjaxCall in our new myScript.js file:
</p></div>
<p><pre class="brush: jscript;">
function AjaxCall()
{
   //do Ajax stuff here....
}
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
We&#8217;ll come back to this in a sec, but first we need to add reference to jQuery library. In our Master page, we&#8217;ll add the script reference, so that the jQuery library can be available to all our pages.</p>
<p>We have two options, either you can type the script tag manually, or you can drag &amp; drop the .js file name from the Solution Explorer onto the Master page. I prefer the latter just because we can in Visual Studio. While we are here, we&#8217;ll create the reference to myScript.js file as well.</p>
<p>Here is what “head” tag of the site.Master page should look like:
</p></div>
<p><pre class="brush: xml;">
&lt;head runat=&quot;server&quot;&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; /&gt;
    &lt;title&gt;&lt;%= Html.Encode(ViewData[&quot;Title&quot;]) %&gt;&lt;/title&gt;
	&lt;link href=&quot;../../Content/Site.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /

    &lt;script src=&quot;../../Scripts/jquery-1.2.6.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;../../Scripts/myScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
Now, back to our AjaxCall() that we had started in our myScript.js file. We will utilize the ajax plugin that is part of the jQuery library: ajax(option).</p>
<p>There are so many different options available that you can use, so please refer to the jQuery.ajax documentation for more details. We will be using the main options that seems to useful in the real world applications:
</p></div>
<p><pre class="brush: jscript;">
$.ajax({
   dataType: “”,
   url: &quot;&quot;,
   beforeSend: function (XMLHttpRequest) {

    },
   success: function (data, textStatus) {
    },
   error: function (XMLHttpRequest, textStatus, errorThrown) {
   }
 });
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
Options:</p>
<ul>
<li><span style="color:#0000ff;">dataType :- This tells the Ajax what kind of data we will be dealing with such as html, xml, json<br />
</span></li>
<li><span style="color:#0000ff;">url :- Where the Ajax call will be made to. In our case, /Controller/Action/<br />
</span></li>
<li><span style="color:#0000ff;">beforeSend :- Do anything before the call is made. I usually use it to display the “loading&#8230;” message.<br />
</span></li>
<li><span style="color:#0000ff;">Success :- When everthing goes well, success function will capture the result.<br />
</span></li>
<li><span style="color:#0000ff;">error :- When there is an error during the Ajax call, error function will let us know.</span></li>
</ul>
<p><span style="color:#0000ff;">We are almost done, hang in there&#8230;</span></p>
<p>When everything does go well and our Ajax call returns the appropriate content. We would like our success function to display the Grid in the place holder that we had added in the beginning.
</p></div>
<p><pre class="brush: jscript;">
$(&quot;#GridContent&quot;).html(data);
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
Lets dissect what&#8217;s happening here:</p>
<ul>
<li><span style="color:#0000ff;">$ :- Represent the jQuery version of document.getElementById() and it also looks up element by class name as well. very handy&#8230;..<br />
</span></li>
<li><span style="color:#0000ff;"># :- Tells the jQuery to lookup element by ID.<br />
</span></li>
<li><span style="color:#0000ff;">GridContent :- Is the ID of our place holder div tag.<br />
</span></li>
<li><span style="color:#0000ff;">html :- Represents the innerHTML property of the element.</span></li>
</ul>
<p>Complete code for the AjaxCall function:
</p></div>
<p><pre class="brush: jscript;">
function AjaxCall()
{
 $.ajax({
   dataType: &quot;html&quot;,
   url: &quot;/Home/GetAjaxGrid/&quot;,
   beforeSend: function (XMLHttpRequest) {
      //Before the Ajax call is made, show the users &quot;loading...&quot; status message
     // within the place holder div.
      $(&quot;#GridContent&quot;).html(&quot;loading...&quot;);
    },
   success: function (data, textStatus) {
      //Render the Grid markup within our place holder that we had created
      //just for this purpose.
      $(&quot;#GridContent&quot;).html(data);
    },
   error: function (XMLHttpRequest, textStatus, errorThrown) {
    //If there are any errors during our Ajax call display them within our place holder as well.
    $(&quot;#GridContent&quot;).html(XMLHttpRequest.responseText);
   }
 });

}
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
Finally, we just need to add onClick event to the our hyperlink that we had added in the Index View.</p>
<p>So back in our Index view, add onClick=”AjaxCall();” to our link.
</p></div>
<p><pre class="brush: xml;">
&lt;a href=&quot;#&quot; onclick=&quot;AjaxCall();&quot;&gt;Make Ajax call&lt;/a&gt;
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
Complete code of the Index View with styles added to make the Grid little prettier:
</div>
<p><pre class="brush: xml;">
&lt;asp:Content ID=&quot;indexContent&quot; ContentPlaceHolderID=&quot;MainContent&quot; runat=&quot;server&quot;&gt;
   &lt;style type=&quot;text/css&quot;&gt;
#GridContent table
{
    border: 1px solid black;
}
#GridContent th
{
    border: 1px solid #000000;
}
#GridContent td
{
    border: 1px solid #000000;
}
#GridContent tr
{
    border: 1px solid #000000;
}
&lt;/style&gt;
    &lt;a href=&quot;#&quot; onclick=&quot;AjaxCall();&quot;&gt;Make Ajax call&lt;/a&gt;
&lt;div id=&quot;GridContent&quot;&gt;&lt;/div&gt;
&lt;/asp:Content&gt;
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
Final output:<br />
<a href="http://ajaxzen.files.wordpress.com/2008/11/finaloutput.png"><img class="alignnone size-full wp-image-52" title="finaloutput" src="http://ajaxzen.files.wordpress.com/2008/11/finaloutput.png?w=452&#038;h=93" alt="finaloutput" width="452" height="93" /></a></p>
<p>Hope you have enjoyed reading the part II as much as I have enjoyed writing it. In the upcoming Part III blog, I&#8217;ll cover how to make our Grid editable. The real cool stuff begins from here on.
</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajaxzen.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajaxzen.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajaxzen.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajaxzen.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajaxzen.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajaxzen.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajaxzen.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajaxzen.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajaxzen.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajaxzen.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajaxzen.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajaxzen.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajaxzen.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajaxzen.wordpress.com/50/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxzen.wordpress.com&amp;blog=5656764&amp;post=50&amp;subd=ajaxzen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajaxzen.wordpress.com/2008/11/30/aspnet-mvc-grid-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/031ed086889313e3f5e928c8f9599cf9?s=96&#38;d=identicon" medium="image">
			<media:title type="html">writer007</media:title>
		</media:content>

		<media:content url="http://ajaxzen.files.wordpress.com/2008/11/scriptfolder1.png" medium="image">
			<media:title type="html">scriptfolder1</media:title>
		</media:content>

		<media:content url="http://ajaxzen.files.wordpress.com/2008/11/finaloutput.png" medium="image">
			<media:title type="html">finaloutput</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET MVC GRID part 1</title>
		<link>http://ajaxzen.wordpress.com/2008/11/27/aspnet-mvc-grid-part-1/</link>
		<comments>http://ajaxzen.wordpress.com/2008/11/27/aspnet-mvc-grid-part-1/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 22:03:33 +0000</pubDate>
		<dc:creator>writer007</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET MVC GRID]]></category>
		<category><![CDATA[GRD]]></category>
		<category><![CDATA[JAVASCRIPT]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[GRID]]></category>
		<category><![CDATA[JQUERY]]></category>

		<guid isPermaLink="false">http://ajaxzen.wordpress.com/?p=3</guid>
		<description><![CDATA[This blog entry is a multi-part series in which our Ajax Master, Tariq Ahmed will show how to develop Ajax driven Grid using ASP.NET MVC Frame Work. These upcoming entries will guide the users in developing a basic to a complicated Grid within ASP.NET MVC Frame Work. Also these entries will utilize jQuery to handle [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxzen.wordpress.com&amp;blog=5656764&amp;post=3&amp;subd=ajaxzen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div style="font-family:verdana;font-size:11px;font-weight:bold;"><span style="color:#0000ff;">This blog entry is a multi-part series in which our Ajax Master, Tariq Ahmed will show how to develop Ajax driven Grid using ASP.NET MVC Frame Work. These upcoming entries will guide the users in developing a basic to a complicated Grid within ASP.NET MVC Frame Work. Also these entries will utilize jQuery to handle all of the Ajax calls. Sweet!!!&#8230; lets begin&#8230;</span></p>
<p><strong><span style="color:#ff0000;">Background:-</span></strong><br />
Today we will start by making a simple grid. Rather than just creating a Grid out of the &lt;table&gt; tag. Why not utilize the Grid control that all of the pre-MVC programmers have been familiar with: GridView. Before we began, allow me to explain little bit about MVC Frame Work. For those who are “Experts” can skip this portion and jump right to the Action section, or you can stick around and read this section as well because wisdom lies in knowing the fundamentals.</p>
<ul>
<li><span style="color:#ff0000;">MVC:- Stands for Model – View – Controller.<br />
</span></li>
<li><span style="color:#ff0000;">MODELs :- Just bunch of Class files that are responsible for maintaining state.<br />
</span></li>
<li><span style="color:#ff0000;">VIEWs :-  Consists of all of the Web Pages such as aspx, ascx, etc. You can also inherit off the model data to generate the View.</span></li>
<li><span style="color:#ff0000;">CONTROLLER: &#8211; Think of controller as the action handler.<br />
i.e User clicks on a link and controller intercepts that event (action). Also, within the Controller you can manipulate the Model.</span></li>
</ul>
<p>Lets dissect the CONTROLLER bit more because usually thats what confuses the new MVC programmers the most.</p>
<p>Controller handles 6 different action types:-</p>
<ol>
<li>ViewResult:- Represent HTML &amp; Markup [ most common ]</li>
<li>EmptyResults:- Represent no results.</li>
<li>RedirectResult:- Redirects to a new URL.</li>
<li>RedirectToRouteResult:- Redirects to a new Controller action.</li>
<li>JsonResult:- Represent json formatted result.</li>
<li>ContentResult:- Represent text result.</li>
</ol>
<p><span style="color:#ff0000;">** All of these action types inherits from the ActionResults base class which is the default return type. **</span></p>
<p>To actually return these action types, you must use the following predefined methods.</p>
<ol>
<li>View():- Returns ViewResult action result.</li>
<li>Redirect():- Returns RedirectResult action.</li>
<li>RedirectToAction():- Returns RedirectToRouteResult action.</li>
<li>RedirectToRoute():- Returns RedirectToRouteResult action.</li>
<li>Json():- Returns Json results.</li>
<li>Content():- Returns ContentResult.</li>
</ol>
<p><span style="color:#008000;">For example:-  HomeController.cs</span>
</div>
<p><pre class="brush: csharp;">
public ActionResult Get()
{
    return View();
}
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
When the Get() action is invoked, it will return a View or a page with a matching name such as Get.aspx located at :- \View\Home\Get.aspx </p>
<p>or you can also specify a different View such as: </p></div>
<p><pre class="brush: csharp;">
public ActionResult Get()
{
   return View(&quot;Foo&quot;);
}
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
This will assume there a Foo.aspx page located at:- \Views\Home\Foo.aspx</p>
<p><span style="color:#ff0000;">** Name of the folder must match with the name of the Controller, so the MVC Frame Work will know where to find the View.**</span></p>
<p><span style="color:#0000ff;">How to pass data from Controller to the View?</span><br />
When Controller is invoked, it returns “view specific data”, hence ViewData. Think of ViewData dictionary property of ASP.NET MVC Frame Work as the content that get returned from Controller. The content can be a Web Page as I mentioned earlier or even Custom Objects (you will see an example of this later). </p>
<p><span style="color:#0000ff;">How do I access ViewData within a Web Page?</span><br />
When you add a Web Page (view) to the project with the appropriate directory ofcourse, you will notice that the page will be derived from “ViewPage” class. Compared to before in regular ASP.NET where a Web Page (Web Form) derived from “System.Web.UI. Page” class. </p>
<p>In ASP.NET MVC, “System.Web.Mvc.ViewPage” is a subclass of the existing “System.Web.UI. Page” class. ViewPage class will give us the access to the ViewData dictionary property that we can use to access the content that was returned from the Controller. Naturally, this is simple concept to grasp after understanding core concept, isn&#8217;t that right?</p>
<p><span style="color:#0000ff;">How do I render the content of ViewData onto the Web Page?</span><br />
Depends on the content, if it is just a string value or even an HTML markup. </p>
<ul>
<li>You can use: <span style="color:#ff0000;">&lt;%= </span><em><span style="color:#ff0000;">Some Code</span></em><span style="color:#ff0000;"> %&gt;</span> :- Represents Response.Write();</li>
<li>On the other hand, you can use: <span style="color:#ff0000;">&lt;% </span><em><span style="color:#ff0000;">Some Code</span></em><span style="color:#ff0000;"> %&gt;</span> :- Allows you implement any compilable code either of C# or VB.NET.</li>
</ul>
<p>This ends our background section.</p>
<p><strong><span style="color:#ff0000;">Action:-</span></strong><br />
Finally, we will built a simple but functional Grid and in the upcoming series we will expand on this using jQuery and Ajax to add more complex functionalities that will meet the real world demands. </p>
<p><span style="color:#008000;">Goal:- </span><br />
When were are done, our final output will look the following:-<br />
<img class="size-full wp-image-4 alignnone" src="http://ajaxzen.files.wordpress.com/2008/11/outputfinal.png?w=460&#038;h=142" alt="Final Result" width="460" height="142" /></p>
<p>Start with blank ASP.NET MVC application, I&#8217;m using Visual Studio 2008 with MVC Beta.<br />
<span style="color:#ff0000;">File &gt;&gt; New Project &gt;&gt; ASP.NET MVC Application</span><br />
<img class="alignnone size-full wp-image-6" title="newprojwizard" src="http://ajaxzen.files.wordpress.com/2008/11/newprojwizard.png?w=309&#038;h=334" alt="newprojwizard" width="309" height="334" /></p>
<p><span style="color:#ff0000;">After you have completed the create new project wizard, Visual Studio 2008 solution explorer should look like this:</span></p>
<p><img class="alignnone size-full wp-image-7" title="solutionexp" src="http://ajaxzen.files.wordpress.com/2008/11/solutionexp.png?w=127&#038;h=262" alt="solutionexp" width="127" height="262" /></p>
<p><span style="color:#ff0000;">Under Scripts folder, Visual Studio 2008 have added for us the necessary jQuery libraries that we need. Very cool&#8230; By the way, VS 2008 also give us the intelli-Sense for JavaScript and with the downloadable plug-in you can get intelli-Sense for jQuery as well. </span></p>
<p><img class="alignnone size-full wp-image-8" title="scriptfolder" src="http://ajaxzen.files.wordpress.com/2008/11/scriptfolder.png?w=192&#038;h=58" alt="scriptfolder" width="192" height="58" /></p>
<p><span style="color:#ff0000;">Our Controller folder should look like this:</span></p>
<p><img class="alignnone size-full wp-image-9" title="controllerfolder" src="http://ajaxzen.files.wordpress.com/2008/11/controllerfolder.png?w=190&#038;h=68" alt="controllerfolder" width="190" height="68" /></p>
<p>We are not interested in the AccountController.cs but we are mainly interested in HomeController.cs file.</p>
<p><span style="color:#ff0000;">HomeController.cs class should look like the following:-</span></p>
<p><img class="alignnone size-full wp-image-10" title="homecontroller1" src="http://ajaxzen.files.wordpress.com/2008/11/homecontroller1.png?w=460&#038;h=252" alt="homecontroller1" width="460" height="252" /></p>
<p><span style="color:#ff0000;">When you run the project as it is, it should look like this: </span></p>
<p><img class="alignnone size-full wp-image-11" title="output1" src="http://ajaxzen.files.wordpress.com/2008/11/output1.png?w=439&#038;h=179" alt="output1" width="439" height="179" /></p>
<p><span style="color:#ff0000;">Now lets add Models to our project, under the Models folder, add two new Classes called MVCGridModel.cs and GridEntity:</span></p>
<p><img class="alignnone size-full wp-image-12" title="addnewclass" src="http://ajaxzen.files.wordpress.com/2008/11/addnewclass.png?w=344&#038;h=207" alt="addnewclass" width="344" height="207" /></p>
<p><img class="alignnone size-full wp-image-13" title="modelfolder" src="http://ajaxzen.files.wordpress.com/2008/11/modelfolder.png?w=168&#038;h=58" alt="modelfolder" width="168" height="58" /></p>
<p><span style="color:#ff0000;">We will define our MVCGridModel.cs class little later, but for now lets define our GridEntity.cs class. </span></p>
<p><span style="color:#ff0000;">GridEntity.cs is our custom object class that we will use to bind our Grid. Properties IndexField and ValueField represents our columns in our Grid.</span></p>
<p><img class="alignnone size-full wp-image-14" title="gridentity" src="http://ajaxzen.files.wordpress.com/2008/11/gridentity.png?w=297&#038;h=278" alt="gridentity" width="297" height="278" /></p>
<p><span style="color:#ff0000;">Now lets define the MVCGridModel, which you will soon realize is very straight forward:</span></p>
<p>Our main ingredient in our model is the GridView which we will inherit from System.Web.UI.WebControls class.</p>
<p>First, create a new public method called GetResults which will return a string, you will see why later.
</p></div>
<p><pre class="brush: csharp;">
public string GetResults()
{
    //create dynamic grid here
}
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
Inside our GetResults method, instantiate a new GridView object.<br />
<span style="color:#ff0000;">GridView gv = new GridView();</span></p>
<p>Since, we don&#8217;t need to display the footer, we can just set it to false.<br />
<span style="color:#ff0000;">gv.ShowFooter = false;</span></p>
<p>I usually set the width to 100%, so that the Grid can expand and shrink automatically when the user resize the browser.<br />
<span style="color:#ff0000;">gv.Width = Unit.Percentage(100);</span></p>
<p>GridView exposes AutoGenerateColumns attribute, which is set to true by default. The purpose of this attribute is to render all data fields that it can AS THEY ARE and by setting it to false, we can control how our columns will be displayed.<br />
<span style="color:#ff0000;">gv.AutoGenerateColumns = false;</span></p>
<p>There is a cool attribute that GridView provide is called RenderControl. RenderControl attribute is probably one of the least used attribute by the .NET programmers, therefore not many of them are aware of the awesome functionality it has. The main function of this attribute is the render entire GridView in <strong>pure</strong> HTML. It is kind of like similar to building the Grid manually out of the &lt;Table&gt; tags. So, why not take advantage of this “badass” feature.</p>
<p>To use RenderControl attribute we need to bring in two other key players: StringWriter &amp; HtmlTextWriter.</p>
<ul>
<li>RenderControl attribute outputs the content to HtmlTextWriter object.</li>
<li>HtmlTextWriter outputs the markup content to StringWriter stream.</li>
</ul>
</div>
<p><pre class="brush: csharp;">
using (StringWriter sw = new StringWriter()) 
{
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    gv.RenderControl(hw);
    hw.Flush();
    string gridMarkUp = hw.InnerWriter.ToString();
}
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
Finally, we need to bind the Grid.</p>
<p>We need a collection of object that we can use to bind our Grid&#8217;s DataSource. Best way we can do that is to use our GridEntity object that we created earlier and create a Collection List.
</p></div>
<p><pre class="brush: csharp;">
private List&lt;GridEntity&gt; GetData()
{
	//Instantiate our GridEntity object as a new List Collection
	List&lt;GridEntity&gt; lst = new List&lt;GridEntity&gt;();

	GridEntity obj; //Instantiate GridEntity object
        obj = new GridEntity();
        obj.IndexField = 1; //Represent the Primary Key of the DataBase table.
        obj.ValueField = &quot;Column one&quot;; //Represent column field.
        lst.Add(obj); //append Custom object to the Collection.

        //Repeat above process to create as many Rows you want
        obj = new GridEntity();
        obj.IndexField = 2;
        obj.ValueField = &quot;Column two&quot;;
        lst.Add(obj);
        return lst; // Return our Collection List
}
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
Here is the complete code of the MVCGridModel.cs: 
</div>
<p><pre class="brush: csharp;">
public class MVCGridModel
{
        public MVCGridModel()
        {
        }

        public string GetResults()
        {
            string gridMarkUp = string.Empty;

            GridView gv = new GridView();
            gv.ShowFooter = false;
            gv.Width = Unit.Percentage(100);
            gv.AutoGenerateColumns = false;

            BoundField col;
            col = new BoundField();
            col.DataField = &quot;IndexField&quot;;
            col.HeaderText = &quot;Perimary Field&quot;;
            gv.Columns.Add(col);

            col = new BoundField();
            col.DataField = &quot;ValueField&quot;;
            col.HeaderText = &quot;Value Field&quot;;
            gv.Columns.Add(col);

            gv.DataSource = GetData();
            gv.DataBind();
            using (StringWriter sw = new StringWriter())
            {
                HtmlTextWriter hw = new HtmlTextWriter(sw);
                gv.RenderControl(hw);
                hw.Flush();
                gridMarkUp = hw.InnerWriter.ToString();
            }

            return gridMarkUp;
        }

        private List&lt;GridEntity&gt; GetData()
        {
            List&lt;GridEntity&gt; lst = new List&lt;GridEntity&gt;();
            GridEntity obj;

            obj = new GridEntity();
            obj.IndexField = 1;
            obj.ValueField = &quot;Column one&quot;;
            lst.Add(obj);

            obj = new GridEntity();
            obj.IndexField = 2;
            obj.ValueField = &quot;Column two&quot;;
            lst.Add(obj);

            return lst;
        }
}
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
Hang in there, we are almost done. We just need to create the View and render our cool Grid. </p>
<p>First, we will create the action in our Home controller and than use the built-in option in VS 2008 to add a new View to the project. Cool&#8230;..</p>
<p>create a new action:
</p></div>
<p><pre class="brush: csharp;">
public ActionResult GetGrid()
{
    //var type is the implicit variable type declartion.
      var model = new MVCGridModel();
      return View(model);
}
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
<strong>var</strong> is the keyword supported by the MVC Frame work that allows you to implicitly declare a variable without having to specify the type. As a JavaScript programmer, I appreciate the implicit variable declaration and wished it could be possible in C#. Now it is, sweet!!!</p>
<p><span style="color:#0000ff;">example:</span><br />
<span style="color:#ff0000;">var i = 5; </span><br />
<span style="color:#008000;">// Represents an integer type.</span><br />
<span style="color:#ff0000;">var j = “This a string”; </span><br />
<span style="color:#008000;">// Represents a string type variable.</span></p>
<p>Here is the complete code of our Home Controller:
</p></div>
<p><pre class="brush: csharp;">
public class HomeController : Controller
{
        public ActionResult Index()
        {
            ViewData[&quot;Title&quot;] = &quot;Home Page&quot;;
            ViewData[&quot;Message&quot;] = &quot;Welcome to ASP.NET MVC!&quot;;

            return View();
        }

        public ActionResult About()
        {
            ViewData[&quot;Title&quot;] = &quot;About Page&quot;;

            return View();
        }

        public ActionResult GetGrid()
        {
            //var type is the implicit variable type declartion.
            var model = new MVCGridModel();
            return View(model);
        }
}
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
Now, for the final piece of the puzzle, the View itself. </p>
<p>When you Right-Click within our <span style="color:#ff0000;">GetGrid()</span> action, VS 2008 will provide you with “Add View” option that is now part of the context menu.</p>
<p><img class="alignnone size-full wp-image-16" title="addviewcontextmenu" src="http://ajaxzen.files.wordpress.com/2008/11/addviewcontextmenu.png?w=187&#038;h=86" alt="addviewcontextmenu" width="187" height="86" /></p>
<p>When you select Add View, you will get the following window:</p>
<p><img class="alignnone size-full wp-image-17" title="addviewwindow" src="http://ajaxzen.files.wordpress.com/2008/11/addviewwindow.png?w=415&#038;h=317" alt="addviewwindow" width="415" height="317" /></p>
<p>Couple of things are happening here:</p>
<ul>
<li>View name: This will be automatically populated for you because as we talked about this earlier, the action name and View has to be the same.</li>
<li>First check box: Here you have the option to utilized the Model or another other custom objects that your view can inherit.</li>
<li>Second check box: Very straight forward, this tell whether you want your View to be part of the master page or not. In our case we want this view to be part of the master page.</li>
</ul>
<p>When you hit add, your view will be automatically added to the appropriate folder:</p>
<p><img class="alignnone size-full wp-image-18" title="homeviewfolder" src="http://ajaxzen.files.wordpress.com/2008/11/homeviewfolder.png?w=143&#038;h=73" alt="homeviewfolder" width="143" height="73" /></p>
<p>the HTML code of our View should look like this:
</p></div>
<p><pre class="brush: xml;">
&lt;%@ Page Title=&quot;&quot; Language=&quot;C#&quot; MasterPageFile=&quot;~/Views/Shared/Site.Master&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;GetGrid.aspx.cs&quot; Inherits=&quot;MVCGridApp.Views.Home.GetGrid&quot; %&gt;
&lt;asp:Content ID=&quot;Content1&quot; ContentPlaceHolderID=&quot;MainContent&quot; runat=&quot;server&quot;&gt;
&lt;/asp:Content&gt;
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
And the Code behind:
</div>
<p><pre class="brush: csharp;">
namespace MVCGridApp.Views.Home
{
    public partial class GetGrid : ViewPage&lt;MVCGridModel&gt;
    {
    }
}
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
Talk about convenience&#8230;.. I&#8217;m sure many AP.NET MVC programmer who had worked on the earlier versions of the Frame Work, will definitely appreciate this functionality. </p>
<p>Now, we will add something in our code behind that will give us little bit advantage. I like to add a public property that will return the ViewData.
</p></div>
<p><pre class="brush: csharp;">
public partial class GetGrid : ViewPage&lt;MVCGridModel&gt;
{
     //public property makes it lot easier for typing.
     //Instead of doing ViewData.Model, I can just do Model.something. Handy little trick to keep
     //things simple as possbile.
       public MVCGridModel Model
       {
           get { return ViewData.Model; }
       }
}
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
In our HTML code, I like to utilize div tags mainly because we can control the layout (ie. styles) and keep things organized:</p>
<p><span style="color:#ff0000;">&lt;div id=&#8221;gvContent&#8221;&gt;&lt;%= Model.GetResults() %&gt;&lt;/div&gt;</span></p>
<p>If you remember back in our MVCGridModel we had created a <span style="color:#ff0000;">GetResults()</span> method that returns the HTML markup string of the GridView control. So by doing <span style="color:#ff0000;">&lt;%= Model.GetResults() %&gt;</span> within the div tag, our entire Grid will be embedded in the div. You will see the advantage of this when we apply the CSS styles to it. </p>
<p>This is the complete HML code of our View:
</p></div>
<p><pre class="brush: xml;">
&lt;asp:Content ID=&quot;Content1&quot; ContentPlaceHolderID=&quot;MainContent&quot; runat=&quot;server&quot;&gt;
&lt;style type=&quot;text/css&quot;&gt;
#gvContent table
{
    border: 1px solid black;

}
#gvContent th
{
    border: 1px solid #000000;

}

#gvContent td
{
    border: 1px solid #000000;

}

#gvContent tr
{
    border: 1px solid #000000;

}

&lt;/style&gt;
&lt;div id=&quot;gvContent&quot;&gt;&lt;/div&gt;
</pre></p>
<div style="font-family:verdana;font-size:11px;font-weight:bold;">
By doing this you will have full control of every aspect of your Grid, soon you will see what I mean in upcoming Part II. </p>
<p>There are many ways to built a Grid and this happens to be one of them.
</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajaxzen.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajaxzen.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajaxzen.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajaxzen.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajaxzen.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajaxzen.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajaxzen.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajaxzen.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajaxzen.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajaxzen.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajaxzen.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajaxzen.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajaxzen.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajaxzen.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxzen.wordpress.com&amp;blog=5656764&amp;post=3&amp;subd=ajaxzen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajaxzen.wordpress.com/2008/11/27/aspnet-mvc-grid-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/031ed086889313e3f5e928c8f9599cf9?s=96&#38;d=identicon" medium="image">
			<media:title type="html">writer007</media:title>
		</media:content>

		<media:content url="http://ajaxzen.files.wordpress.com/2008/11/outputfinal.png" medium="image">
			<media:title type="html">Final Result</media:title>
		</media:content>

		<media:content url="http://ajaxzen.files.wordpress.com/2008/11/newprojwizard.png" medium="image">
			<media:title type="html">newprojwizard</media:title>
		</media:content>

		<media:content url="http://ajaxzen.files.wordpress.com/2008/11/solutionexp.png" medium="image">
			<media:title type="html">solutionexp</media:title>
		</media:content>

		<media:content url="http://ajaxzen.files.wordpress.com/2008/11/scriptfolder.png" medium="image">
			<media:title type="html">scriptfolder</media:title>
		</media:content>

		<media:content url="http://ajaxzen.files.wordpress.com/2008/11/controllerfolder.png" medium="image">
			<media:title type="html">controllerfolder</media:title>
		</media:content>

		<media:content url="http://ajaxzen.files.wordpress.com/2008/11/homecontroller1.png" medium="image">
			<media:title type="html">homecontroller1</media:title>
		</media:content>

		<media:content url="http://ajaxzen.files.wordpress.com/2008/11/output1.png" medium="image">
			<media:title type="html">output1</media:title>
		</media:content>

		<media:content url="http://ajaxzen.files.wordpress.com/2008/11/addnewclass.png" medium="image">
			<media:title type="html">addnewclass</media:title>
		</media:content>

		<media:content url="http://ajaxzen.files.wordpress.com/2008/11/modelfolder.png" medium="image">
			<media:title type="html">modelfolder</media:title>
		</media:content>

		<media:content url="http://ajaxzen.files.wordpress.com/2008/11/gridentity.png" medium="image">
			<media:title type="html">gridentity</media:title>
		</media:content>

		<media:content url="http://ajaxzen.files.wordpress.com/2008/11/addviewcontextmenu.png" medium="image">
			<media:title type="html">addviewcontextmenu</media:title>
		</media:content>

		<media:content url="http://ajaxzen.files.wordpress.com/2008/11/addviewwindow.png" medium="image">
			<media:title type="html">addviewwindow</media:title>
		</media:content>

		<media:content url="http://ajaxzen.files.wordpress.com/2008/11/homeviewfolder.png" medium="image">
			<media:title type="html">homeviewfolder</media:title>
		</media:content>
	</item>
	</channel>
</rss>
