<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>gridview &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://wordpress.com/tag/gridview/</link>
	<description>Feed of posts on WordPress.com tagged "gridview"</description>
	<pubDate>Mon, 06 Oct 2008 14:44:02 +0000</pubDate>

	<generator>http://wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[how to show gridview if it doesn't have records]]></title>
<link>http://chandu2u.wordpress.com/?p=92</link>
<pubDate>Sat, 04 Oct 2008 10:28:55 +0000</pubDate>
<dc:creator>chandramohan</dc:creator>
<guid>http://chandu2u.it.wordpress.com/2008/10/04/how-to-show-gridview-if-it-doesnt-have-records/</guid>
<description><![CDATA[to dispaly the gridview when no records are avilable
create EmptyDataTemplate
&lt;asp:GridView ID=]]></description>
<content:encoded><![CDATA[<p>to dispaly the gridview when no records are avilable</p>
<p>create EmptyDataTemplate</p>
<p>&#60;asp:GridView ID="fd" runat="server" AutoGenerateColumns="false"&#62;<br />
&#60;EmptyDataTemplate&#62;<br />
No record availble here<br />
&#60;/EmptyDataTemplate&#62;<br />
&#60;Columns&#62;</p>
<p>&#60;/Columns&#62;<br />
&#60;/asp:GridView&#62;</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Manipulate GridView Rows, Cells, Cell Controls from JavaScript]]></title>
<link>http://programminghack.wordpress.com/?p=27</link>
<pubDate>Fri, 26 Sep 2008 03:51:16 +0000</pubDate>
<dc:creator>kinjanshah</dc:creator>
<guid>http://programminghack.it.wordpress.com/2008/09/26/manipulate-gridview-rows-cells-cell-controls-from-javascript/</guid>
<description><![CDATA[In one of the functionalities I was developing, I needed to integrate my GridView with JavaScript. I]]></description>
<content:encoded><![CDATA[<p>In one of the functionalities I was developing, I needed to integrate my GridView with JavaScript. I mean I was supposed to change the text in few cells of GridView. So, I dig it little bit and found out a way as I have shown below.</p>
<p><strong>Accessing GridView rows/cells from JavaScript:</strong></p>
<p style="padding-left:30px;">&#60;script type="text/javascript" language="javascript"&#62;</p>
<p style="padding-left:60px;">tblTable=document.getElementById('&#60;&#60;Client ID of the GridView&#62;&#62;');<br />
Cell=tblTable.rows[0].cells[0];<br />
Cell.innerHTML='Hurra!!!!! I have accessed the first row, first cell';</p>
<p style="padding-left:30px;">&#60;/script&#62;</p>
<p><strong>Accessing GridView Rows/cells and Cell Control from JavaScript:</strong><br />
Isn't it a great way to access GridView from JavaScript?</p>
<p style="padding-left:30px;">&#60;script type="text/javascript"&#62;</p>
<p style="padding-left:60px;">tblTable=document.getElementById('&#60;&#60;Client ID of the GridView&#62;&#62;');<br />
Cell=tblTable.rows[0].cells[0];<br />
FirstControl = Cell.childNodes[0];</p>
<p style="padding-left:30px;">&#60;/script&#62;</p>
<p>Hope this will help you out.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[To get the selected row value in gridview]]></title>
<link>http://chandu2u.wordpress.com/?p=65</link>
<pubDate>Thu, 25 Sep 2008 06:51:27 +0000</pubDate>
<dc:creator>chandramohan</dc:creator>
<guid>http://chandu2u.it.wordpress.com/2008/09/25/to-get-the-selected-row-value-in-gridview/</guid>
<description><![CDATA[protected void gvsample_SelectedIndexChanged(object sender, EventArgs e)
{
string  t1 = ((LinkButto]]></description>
<content:encoded><![CDATA[<p>protected void gvsample_SelectedIndexChanged(object sender, EventArgs e)<br />
{<br />
string  t1 = ((LinkButton)gvsample.SelectedRow.Cells[3].FindControl("lnkSno")).Text;</p>
<p>//here lnksno is control id and cells[3] means link button is the third column of the gridview</p>
<p>}</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[To get the selected row index of gridview]]></title>
<link>http://chandu2u.wordpress.com/?p=63</link>
<pubDate>Thu, 25 Sep 2008 06:47:53 +0000</pubDate>
<dc:creator>chandramohan</dc:creator>
<guid>http://chandu2u.it.wordpress.com/2008/09/25/to-get-the-selected-row-index-of-gridview/</guid>
<description><![CDATA[for getting this we should design the grid using templats
here lblsno is the id of the item template]]></description>
<content:encoded><![CDATA[<p>for getting this we should design the grid using templats</p>
<p>here lblsno is the id of the item template control</p>
<p>string t1 = ((Label)gvsample.Rows[e.RowIndex].FindControl("lblsno")).Text;</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Hierarchical Gridview]]></title>
<link>http://vgermain.wordpress.com/?p=9</link>
<pubDate>Tue, 23 Sep 2008 13:38:57 +0000</pubDate>
<dc:creator>Vincent Germain</dc:creator>
<guid>http://vgermain.it.wordpress.com/2008/09/23/hierarchical-gridview/</guid>
<description><![CDATA[After using many professional/commercial controls, I was often disappointed in using them. When you ]]></description>
<content:encoded><![CDATA[<p>After using many professional/commercial controls, I was often disappointed in using them. When you are following the simple sample path, it will work. But if you really want to customize the control, the percent rate of bugs and unwanted states increase. If a control cannot be reliable, it's better to do it and keep a full control on the source code.</p>
<p>That's why, rather than spending some money to own your multi-gridview and waiting each day after a patch, here is a cool tip to adapt a standard Gridview in hierarchical Gridview:</p>
<p>Create a standard GridView on a webform and create a template field column at the end of the columns collection. Add in the template item : "&#60;tr&#62;&#60;td&#62; Second Row &#60;/td&#62;&#60;/tr&#62;".</p>
<p>That all folk ! When addind this code, the DOM structure of the gridview is broken(Yes, it's not W3C). But the result is there. Working with IE,Firefox and Chrome.</p>
<p>If we analyse in deep the generating HTML Code of the gridview, we can see the following structure:</p>
<p><span style="color:#008000;">&#60;table&#62;</span></p>
<p><span style="color:#008000;">&#60;tr&#62;&#60;th&#62;col1&#60;/th&#62;&#60;th&#62;col second row&#60;/th&#62;&#60;/tr&#62;</span></p>
<p><span style="color:#008000;">&#60;tr&#62;&#60;td&#62;col1 value&#60;/td&#62;&#60;td&#62;</span></p>
<p><span style="color:#008000;"> &#60;tr&#62;&#60;td&#62;Second Row&#60;/td&#62;&#60;/tr&#62;</span></p>
<p><span style="color:#008000;"> &#60;/td&#62;&#60;/tr&#62;</span></p>
<p><span style="color:#008000;">&#60;/table&#62;</span></p>
<p>When adding TR in td(cell of gridview), a new row is created. However, we can manage the visibility of this new row through cell properties. Thus, with an appropriate extender(link,image,other control), we can hide or show the row.</p>
<p>I have created for my personal purpose 2 definition of template Field Column that I can add to a gridview and render it like a Hierarchical Gridview.</p>
<p>Here the code:</p>
<p><a href="http://vgermain.files.wordpress.com/2008/09/subrowboundfield.doc">subrowboundfield</a></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Ngambil nilai dari GridView]]></title>
<link>http://ginanwords.wordpress.com/?p=11</link>
<pubDate>Mon, 15 Sep 2008 06:11:41 +0000</pubDate>
<dc:creator>Ginan</dc:creator>
<guid>http://ginanwords.it.wordpress.com/2008/09/15/ngambil-nilai-dari-gridview/</guid>
<description><![CDATA[Wuih, da ide lagi nih. Barusan gw liat-liat code kerjaan gw, ternyata, gw nemu sesuatu yang menarik.]]></description>
<content:encoded><![CDATA[<p>Wuih, da ide lagi nih. Barusan gw liat-liat code kerjaan gw, ternyata, gw nemu sesuatu yang menarik. Berkaitan dengan gimana cara ngambil value dari sebuah GridView. Well, gini nih caranya...</p>
<p>Klo lo punya GridView columns dengan type BoundField, maka cara ngambilnya akan seperti ini:</p>
<pre><span style="color:#ff0000;">GridViewRow fRow = GridViewName.Rows[RowIndex];
TableCell fCell = fRow.Cells[CellIndex];
string fResult = fCell.Text;

</span></pre>
<p><br><br />
Nah, klo type columns-nya TemplateField, lo harus nyari dulu control yang nyimpen datanya dimana... Contohnya lo mau ngambil value yang ada di Label grade.</p>
<pre><span style="color:#ff0000;">GridViewRow fRow = GridViewName.Rows[RowIdx];
Label grade = (Label)fRow.FindControl("grade");
string fResult = "";
if (grade != null)
{
   fResult = grade.Text;
}

</span></pre>
<p><br><br />
Gitu doang, mudah kan?</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[IT throughput at the LHC data grid]]></title>
<link>http://theplummetonions.wordpress.com/?p=3201</link>
<pubDate>Sat, 13 Sep 2008 08:41:26 +0000</pubDate>
<dc:creator>Timinator</dc:creator>
<guid>http://theplummetonions.it.wordpress.com/2008/09/13/it-throughput-at-the-lhc-data-grid/</guid>
<description><![CDATA[A post this week from a work-related blog I read mentioned the Large Hadron Collider. This post was ]]></description>
<content:encoded><![CDATA[<p>A post this week from a work-related blog I read mentioned the Large Hadron Collider. This post was not really about the LHC itself, or CERN, or the experiments they're doing, which have already been heavily covered recently. It was about the massive data collection network involved in the experimentation.</p>
<p><a href="http://lcg.web.cern.ch/LCG/">This page from CERN</a> has information about the LHC Computing Grid (LCG). If you're into data centres, have a read.</p>
<p>Having worked in networking for many years I find the <a href="http://gridview.cern.ch/GRIDVIEW/">data throughput visualization tools</a> to be really interesting. You can see, hour by hour, the amount of data throughput for all the different experiments that make up the LHC. A couple of hours before I wrote this they hit 380 megabytes per second across all systems, with <a href="http://aliceinfo.cern.ch/Public/Welcome.html">Alice</a> (where they hope to detect quark-gluon plasma), <a href="http://atlas.ch/">Atlas</a> (where they hope to spot the Higgs boson, evidence of dark matter, and answer questions about whether there might be a higher number of spacetime dimensions than we think there are), and <a href="http://cmsinfo.cern.ch/outreach/">CMS</a> (similar to Atlas, but using different methods of detection) being by the largest.</p>
<p>Switch to a daily view, though, and you'll see that they're actually in a very low data-collection mode at the moment: there was a local peak around 1250 MB/s back on 24 August. The largest average throughput this year was about 2100 MB/s in late May. Lots of data, and a really neat way of watching progress.</p>
[caption id="attachment_3202" align="aligncenter" width="300" caption="LHC data throughput year to date (click to enlarge)"]<a href="http://theplummetonions.files.wordpress.com/2008/09/gridftp_graphsphp.png"><img class="size-medium wp-image-3202" title="gridftp_graphsphp" src="http://theplummetonions.wordpress.com/files/2008/09/gridftp_graphsphp.png?w=300" alt="LHC data throughput year to date (click to enlarge)" width="300" height="119" /></a>[/caption]
<p>A word on the similar goals of the Atlas/CMS detectors: I heard on BBC Radio 4 the other morning that there's a pretty healthy dose of rivalry between the two scientific teams about who might make their discoveries first.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[GridView içerisindeki verilerin alınması]]></title>
<link>http://abacigil.wordpress.com/?p=10</link>
<pubDate>Sun, 31 Aug 2008 01:11:55 +0000</pubDate>
<dc:creator>abacigil</dc:creator>
<guid>http://abacigil.it.wordpress.com/2008/08/31/gridview-icerisindeki-verilerin-alinmasi/</guid>
<description><![CDATA[.NET platformunu kullanan herkesin en yaygın kullandığı araç GridView&#8217;dir. Database ile y]]></description>
<content:encoded><![CDATA[<div><span style="font-size:85%;font-family:verdana;"><span style="font-size:x-small;">.NET platformunu kullanan herkesin en yaygın kullandığı araç GridView'dir. Database ile yapacağınız listeleme, raporlama vb. tüm ihityaçlarınızı GridView ile giderebilirsiniz. Genel olarak tüm ihityaçları karşılasa da bazen spesifik ihtiyaçlar söz konusu olabilir.</span></span></div>
<div><span style="font-size:85%;font-family:verdana;"><span style="font-size:x-small;">Diyelim ki, GridView kullanarak veritabanından veri akışı sağladınız ve ortaya çıkan tablodaki bazı alanlara ait değerleri elde etmek istiyorsunuz. Siz bir GridView'e bağlantı yaptığınızda ve GridView özelliklerinde "Enable Selection" dediğinizde GridView'in Properties özelliklerindeki "DataKeyNames"'de bulunan alanı baz alır. </span></span></div>
<div><span style="font-size:85%;font-family:verdana;"><span style="font-size:85%;font-family:verdana;"><span style="font-size:x-small;">Aşağıdaki örnekte Default olarak belirlenen "DataKeyNames" özelliği karşısında "UyeIsYeriID" var. Fakat ben "Seç" tuşuna bastığımda "Üye Adını" almak istiyorum. Yani bu işlem sonucunda ekranda Label'ım üzerinde "Kıtır" yazısı gözükecek.</span></span></span></div>
<div> </div>
<div><span style="font-size:85%;font-family:verdana;"><span style="font-size:85%;font-family:verdana;"><span style="font-size:x-small;"><strong>Bunun için öncelikle, GridView'in Edit Items seçeneğine tıklayıp, "Seç" tuşuna bastığınızda almak istediğiniz alanı "Convert this field into a TemplateField" seçeneği ile düzenlenebilir hale getirmeniz gerekmekte.</strong></span></span></span></div>
<div><span style="font-size:85%;font-family:verdana;"><span style="font-size:85%;font-family:verdana;"><strong></strong></span></span></div>
<div><span style="font-size:85%;font-family:verdana;"><span style="font-size:85%;font-family:verdana;"><span style="font-size:x-small;"><a href="http://abacigil.files.wordpress.com/2008/08/ekran-alintisi.jpg"><img class="alignnone size-full wp-image-11" src="http://abacigil.wordpress.com/files/2008/08/ekran-alintisi.jpg" alt="" width="635" height="142" /></a></span></span></span></div>
<div><span style="font-size:85%;font-family:verdana;"><span style="font-size:85%;font-family:verdana;"></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:Verdana;">protected</span><span style="font-size:10pt;font-family:Verdana;"> <span style="color:#0000ff;">void</span> GridView1_RowCommand(<span style="color:#0000ff;">object</span> sender, GridViewCommandEventArgs e)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;"><span>        </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;"><span>        </span><span style="color:#0000ff;">int</span> index = <span style="color:#2b91af;">Convert</span>.ToInt32(e.CommandArgument);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;"><span>        </span>GridViewRow row = GridView1.Rows[index];</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;"><span>        </span>Label1.Text = row.Cells[1].Text; </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">}</span></p>
<p class="MsoNormal" style="margin:0;"> Not: Bu kodu aynen çalıştırdığınızda, GridView üzerinden verilen tüm komutlar bu kodları çalıştıracak. Bunu engellemek amacıyla,<br />
<strong>if(e.CommandName == "Select")</strong> şartını kullanabilirsiniz.</p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:Verdana;">Şimdi burada row.Cells[1].Text kısmında, 1'in anlamı, almak istediğiniz verinin bulunduğu hücre. Bunu GridView'in "Edit Templates" seçeneğine tıklayarak, karşınıza çıkan küçük düzenlenebilir alandan öğrenebilirsiniz.</span></p>
<p> <br></p>
<p> </p>
<p> </p>
<p></span></span></div>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Ordenando un GridView mediante el evento Sorting (El GridView y sus eventos: El evento Sorting)]]></title>
<link>http://adeshoras.wordpress.com/?p=127</link>
<pubDate>Tue, 26 Aug 2008 22:09:33 +0000</pubDate>
<dc:creator>César</dc:creator>
<guid>http://adeshoras.it.wordpress.com/2008/08/27/ordenando-un-gridview-mediante-el-evento-sorting-el-gridview-y-sus-eventos-el-evento-sorting/</guid>
<description><![CDATA[Una de las operaciones típicas a realizar con un GridView, es ordenar la información que muestra, ]]></description>
<content:encoded><![CDATA[<p>Una de las operaciones típicas a realizar con un GridView, es ordenar la información que muestra, ahora vamos a ver como hacerlo mediante el evento Sorting, cuando se ejecuta, cual es su finalidad y que es lo que nos aporta.</p>
<p>Tengo que decir tambien, que junto con <a title="El evento RowDataBound en A deshoras" href="http://adeshoras.wordpress.com/2008/08/09/el-gridview-y-sus-eventos-el-evento-rowdatabound/" target="_blank">el evento RowDataBound para manipular la información antes de hacer el binding</a> y <a title="El evento PageIndexChanging en A deshoras" href="http://adeshoras.wordpress.com/2008/08/15/el-gridview-y-sus-eventos-el-evento-pageindexchanging/" target="_blank">el evento PageIndexChaning para paginar el GridView</a>, este es uno de los más usados.</p>
<p>Como ya hemos visto anteriormente el GridView es un control que nos proporciona ASP.NET cuya funcionalidad es “trabajar” con información tabular. Seguramente es uno de los controles más usados y a lo lardo de las distintas versiones de Visual Studio, ha cambiado el nombre, pero siempre se ha mantenido. Este control, es muy pesado y consume gran cantidad de memoria pero aporta mucha funcionalidad que muchas veces no llegamos a aprovechar porque generalmente lo usamos para mostrar información (entendamos que hablo de aplicaciones Web).</p>
<p>Este post forma parte de una serie de post llamada El GridView y sus Eventos. Los post que forman esta serie y que si has llegado aquí te pueden interesar son:</p>
<ul>
<li><a title="//adeshoras.wordpress.com/" href="http://adeshoras.wordpress.com/2008/08/09/el-gridview-y-sus-eventos-el-evento-rowdatabound/" target="_blank">El GridView y sus eventos: El evento RowDataBound</a>.</li>
<li><a title="El evento PageIndexChanging" href="http://adeshoras.wordpress.com/2008/08/15/el-gridview-y-sus-eventos-el-evento-pageindexchanging/" target="_blank">El GridView y sus eventos: El evento PageIndexChanging</a>.</li>
<li><a title="El evento Sorting) en A deshoras" href="http://adeshoras.wordpress.com/2008/08/27/ordenando-un-gridview-mediante-el-evento-sorting-el-gridview-y-sus-eventos-el-evento-sorting/" target="_blank">Ordenando un GridView mediante el evento Sorting (El GridView y sus eventos: El evento Sorting)</a>.</li>
</ul>
<h3>El evento Sorting.</h3>
<p>El control GridView, como vamos viendo tiene mucha funcionalidad implementada, y parte de esta, es <strong>la  capacidad de ordenación de sus resultados</strong>, lo cual es muy útil. <strong>El evento Sorting, salta cada vez que pulsamos en un link de ordenación, pero antes de que se haya realizado la susodicha ordenación</strong>.<!--more--></p>
<p>Para poder ordenar los resultados mostrados en un GridView, tenemos que setear a true la propiedad <em>AllowSorting</em> y además a cada una de las columna que le hayamos indicado en el tag Columns, tenemos que indicarle cual va a ser su <em>SortExpression</em> y su <em>HeaderText</em>. El <em>SortExpression</em> es la expresión que vamos a ir utilizando para identificar porque columna queremos ordenar los datos y el <em>HeaderText</em>, es el texto que vamos a mostrar.</p>
<p>Veamos un ejemplo, primero el control GridView que tendría este aspecto:</p>
<p><code>&#60;asp:GridView<br />
ID="gvCities"<br />
runat="server"<br />
DataKeyNames="CityCode"<br />
CssClass="cssTableGrid"<br />
AutoGenerateColumns="False"<br />
AllowPaging="true"<br />
AllowSorting="true"<br />
PageSize="15"<br />
OnRowDataBound="GvCities_RowDataBound"<br />
OnPageIndexChanging="GvCities_PageIndexChanging"<br />
OnSorting="GvCities_Sorting"&#62;<br />
&#60;AlternatingRowStyle CssClass="cssTRAlternatingStyle" /&#62;<br />
&#60;Columns&#62;<br />
&#60;asp:TemplateField HeaderText="Ciudad" SortExpression="Name" &#62;<br />
&#60;ItemTemplate&#62;<br />
&#60;asp:Literal ID="ltrlName" runat="server" /&#62;<br />
&#60;/ItemTemplate&#62;<br />
&#60;/asp:TemplateField&#62;<br />
&#60;asp:TemplateField HeaderText="País" SortExpression="CountryName"&#62;<br />
&#60;ItemTemplate&#62;<br />
&#60;asp:Literal ID="ltrlCountry" runat="server" /&#62;<br />
&#60;/ItemTemplate&#62;<br />
&#60;/asp:TemplateField&#62;<br />
&#60;/Columns&#62;<br />
&#60;/asp:GridView&#62;</code></p>
<p>Como podeis ver, la propiedad <em>AllowSorting</em> la hemos seteado a true, y además cada una de las columnas tienen dos campos el <em>SortExpression</em> y el <em>HeaderText</em>.</p>
<p>Ahora veamos el aspecto que tiene el evento:</p>
<p><code>protected void GvCities_Sorting(object sender, GridViewSortEventArgs e){}</code></p>
<p>Como argumentos, recibe el objeto que lo lanza y los <strong>GridViewSortEventArgs</strong> desde los cuales podemos acceder a la dirección (SortDirection) y la expresión que estamos usando (SortExpression).</p>
<p>A partir de aquí, cada uno tendrá que implementar su ordenación, en mi caso como estamos usando unas listas de entidades como fuente de datos, las he ordenado de dos formas distintas, una con linq y la otra con la ordenación que aportan los genéricos.</p>
<h4>Ordenación por medio de linq.</h4>
<p>Las ordenaciones con linq son muy simples, únicamente tenemos que indicarle el campo por el que queremos ordenar mediante una lambda expression.</p>
<p>Para ordenar de forma ascendente sería algo así:</p>
<p><code>cityList.OrderBy(c =&#62; c.Name).ToList();</code></p>
<p>Y para ordenar de forma descendente sería:</p>
<p><code>cityList.OrderByDescending(c =&#62; c.Name).ToList();</code></p>
<p>Entiendase que c es del tipo City.</p>
<h4>Ordenaciones por medio del metodo Sort de las listas genericas.</h4>
<p>Los genéricos y listas de objetos tienen un método implementado por el cual podemos ordenar, en el tenemos que llamar a un delegado que es el que realiza la ordenación.</p>
<p>Una ordenación ascendente por medio de genéricos sería algo así:</p>
<p><code>cityList.Sort(delegate(City x, City y) { return string.Compare(x.Country.Name, y.Country.Name); });</code></p>
<p>Y si una ordenación descente sería igual pero cambiando el lado de los objetos a comparar:</p>
<p><code>cityList.Sort(delegate(City x, City y) { return string.Compare(y.Country.Name, x.Country.Name); });</code></p>
<p>Y hasta aquí llegamos hoy, con este evento cerramos un ciclo ya que de los eventos del GridView que vamos a ver, el RowDataBound, el PageIndexChanging y el Sorting, seguramente son los más usados aunque los que iremos viendo próximamente nos dejan realizar muchas operaciones de una forma sencilla y eficiente.</p>
<h3>Post relacionados.</h3>
<p>Este post forma parte de una serie de post llamada El GridView y sus Eventos. Los post que forman esta serie y que si has llegado aquí te pueden interesar son:</p>
<ul>
<li><a title="//adeshoras.wordpress.com/" href="http://adeshoras.wordpress.com/2008/08/09/el-gridview-y-sus-eventos-el-evento-rowdatabound/" target="_blank">El GridView y sus eventos: El evento RowDataBound</a>.</li>
<li><a title="El evento PageIndexChanging" href="http://adeshoras.wordpress.com/2008/08/15/el-gridview-y-sus-eventos-el-evento-pageindexchanging/" target="_blank">El GridView y sus eventos: El evento PageIndexChanging</a>.</li>
<li><a title="El evento Sorting) en A deshoras" href="http://adeshoras.wordpress.com/2008/08/27/ordenando-un-gridview-mediante-el-evento-sorting-el-gridview-y-sus-eventos-el-evento-sorting/" target="_blank">Ordenando un GridView mediante el evento Sorting (El GridView y sus eventos: El evento Sorting)</a>.</li>
</ul>
<h3>Descargas - Downloads.</h3>
<ul>
<li><a title="//adeshoras.wordpress.com/" href="http://cid-4aa6af1b4a447319.skydrive.live.com/self.aspx/a-deshoras-aplicaciones-y-codigos-de-ejemplo/GridViewEventsSolution.zip" target="_blank">Descargate el código de ejemplo usado en este post y seguro que así puedes comprender mejor como funciona el evento RowDataBound.</a></li>
</ul>
<p>Mientras he escrito este post he estado escuchando pop frances de los 60 (y ahora me siento un poco yeyé), asi que aqui os dejo con Marie Laforet  y su version de los Stones.</p>
<p><span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='http://www.youtube.com/v/kgH_I_LoYpk'></param><param name='wmode' value='transparent'></param><embed src='http://www.youtube.com/v/kgH_I_LoYpk&rel=0' type='application/x-shockwave-flash' wmode='transparent' width='425' height='350'></embed></object></span></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Gridview page and row count.]]></title>
<link>http://myrandomcode.wordpress.com/?p=16</link>
<pubDate>Wed, 20 Aug 2008 17:18:52 +0000</pubDate>
<dc:creator>incognito</dc:creator>
<guid>http://myrandomcode.it.wordpress.com/2008/08/20/gridview-page-and-row-count/</guid>
<description><![CDATA[//Gridview page and row count.
&lt;i&gt;You are viewing page &lt;%=productsGridView.PageIndex + 1%]]></description>
<content:encoded><![CDATA[<p><strong>//Gridview page and row count.</strong><br />
&#60;i&#62;You are viewing page &#60;%=productsGridView.PageIndex + 1%&#62; of &#60;%=productsGridView.PageCount%&#62; &#60;/i&#62;</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Store and Retrieve multiple values in the GridView]]></title>
<link>http://asimafzal.wordpress.com/?p=42</link>
<pubDate>Sun, 17 Aug 2008 10:24:48 +0000</pubDate>
<dc:creator>asimafzal</dc:creator>
<guid>http://asimafzal.it.wordpress.com/2008/08/17/store-and-retrieve-multiple-values-in-the-gridview/</guid>
<description><![CDATA[How to store the multiple values when you bind the grid?
1.	Add the multiple fields name in DataKeyN]]></description>
<content:encoded><![CDATA[<p><strong>How to store the multiple values when you bind the grid?</strong></p>
<p>1.	Add the multiple fields name in DataKeyNames with comma separator.<br />
2.	Later on bind you can retrieve the fields value.</p>
<p><strong>DataView.aspx</strong><br />
<em>DataKeyNames="EmpID,EmpName,EmpPhone "</em> </p>
<p><strong>DataView.aspx.cs</strong><br />
<em>DataKey dataRow = grdEmployee.DataKeys[grdEmployee.SelectedRow.DataItemIndex];<br />
lblEmpID.Text = dRow[0].ToString();<br />
lblEmpName.Text = dRow[1].ToString();<br />
lblEmpPhone.Text = dRow[2].ToString();</em></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[El GridView y sus eventos: El evento PageIndexChanging]]></title>
<link>http://adeshoras.wordpress.com/?p=102</link>
<pubDate>Fri, 15 Aug 2008 16:31:30 +0000</pubDate>
<dc:creator>César</dc:creator>
<guid>http://adeshoras.it.wordpress.com/2008/08/15/el-gridview-y-sus-eventos-el-evento-pageindexchanging/</guid>
<description><![CDATA[En este post, vamos a ver el evento PageIndexChanging del GridView. Vamos a ver cuando se ejecuta, c]]></description>
<content:encoded><![CDATA[<p>En este post, vamos a ver el evento PageIndexChanging del GridView. Vamos a ver cuando se ejecuta, cual es su finalidad y lo que nos aporta.</p>
<p>El GridView es un control que nos proporciona ASP.NET cuya funcionalidad es “trabajar” con información tabular. Seguramente es uno de los controles más usados y a lo lardo de las distintas versiones de Visual Estudio, ha cambiado el nombre, pero siempre se ha mantenido. Este control, es muy pesado y consume gran cantidad de memoria pero aporta mucha funcionalidad que muchas veces no llegamos a aprovechar porque generalmente lo usamos para mostrar información (entendamos que hablo de aplicaciones Web).</p>
<p>Este post forma parte de una serie de post llamada El GridView y sus Eventos. Los post que forman esta serie y que si has llegado aquí te pueden interesar son:</p>
<ul>
<li><a title="//adeshoras.wordpress.com/" href="http://adeshoras.wordpress.com/2008/08/09/el-gridview-y-sus-eventos-el-evento-rowdatabound/" target="_blank">El GridView y sus eventos: El evento RowDataBound</a>.</li>
<li><a title="El evento PageIndexChanging" href="http://adeshoras.wordpress.com/2008/08/15/el-gridview-y-sus-eventos-el-evento-pageindexchanging/" target="_blank">El GridView y sus eventos: El evento PageIndexChanging</a>.</li>
<li><a title="El evento Sorting) en A deshoras" href="http://adeshoras.wordpress.com/2008/08/27/ordenando-un-gridview-mediante-el-evento-sorting-el-gridview-y-sus-eventos-el-evento-sorting/" target="_blank">Ordenando un GridView mediante el evento Sorting (El GridView y sus eventos: El evento Sorting)</a>.</li>
</ul>
<h3>El evento PageIndexChanging.</h3>
<p><strong>El GridView, nos aporta la posibilidad de poder paginar los resultados</strong> pudiendo así mostrar cada vez un conjunto de registros. Esto lo conseguimos, si le seteamos a <em>true</em> la propiedad <em>AllowPaging</em>, y también podemos indicarle el número de registros que queremos mostrar cada vez (por defecto, si no recuerdo mal es 10) por medio de la propiedad <em>PageSize</em>.<!--more--></p>
<p>El código necesario sería el siguiente:</p>
<p><code>&#60;asp:GridView<br />
ID="gvCities"<br />
runat="server"<br />
DataKeyNames="CityCode"<br />
CssClass="cssTableGrid"<br />
AutoGenerateColumns="False"<br />
AllowPaging="true"<br />
PageSize="15"<br />
OnPageIndexChanging="GvCities_PageIndexChanging"&#62; &#60;/asp:GridView&#62;</code></p>
<p>Cuando seteamos la propiedad <strong><em>AllowPaging</em> a <em>true</em>, además de mostrar los resultados de forma paginada, nos muestra en la parte inferior del control un control de paginación</strong> (<a title="//adeshoras.wordpress.com/" href="http://adeshoras.wordpress.com/2008/06/10/yahoo-design-patterns-patrones-de-diseno-definidos-por-yahoo-navegaciones-en-busquedas-de-datos/" target="_blank">que no cumple las guidelines que vimos anteriormente, pero menos da una piedra ;-)</a>).</p>
<p>El evento <strong>PageIndexChanging, se levanta cada vez que pulsamos en uno de los links del control de paginación</strong>. La implementación sería algo así:</p>
<p><code>protected void GvCities_PageIndexChanging(object sender, GridViewPageEventArgs e)<br />
{<br />
GridView gv = (GridView)sender;<br />
gv.PageIndex = e.NewPageIndex;<br />
bindCitiesGrid();<br />
}</code></p>
<p>En los argumentos del evento (del tipo <em>GridViewPageEventArgs</em>), recibimos el nuevo indice de página, este, unicamente tenemos que asignarselo a la propiedad <em>PageIndex</em> del GridView y ya esta todo hecho, la proxima que hagamos el binding del control nos mostrara el conjunto que esperamos.</p>
<p>Sencillo verdad, pues esto es todo. Podeis probar a poner el GridView (como en el código de ejemplo :-D) dentro de UpdatePanel y vereis como el resultado es bastante aparente (costando muy poco trabajo).</p>
<h3>Post relacionados.</h3>
<p>Este post forma parte de una serie de post llamada El GridView y sus Eventos. Los post que forman esta serie y que si has llegado aquí te pueden interesar son:</p>
<ul>
<li><a title="//adeshoras.wordpress.com/" href="http://adeshoras.wordpress.com/2008/08/09/el-gridview-y-sus-eventos-el-evento-rowdatabound/" target="_blank">El GridView y sus eventos: El evento RowDataBound</a>.</li>
<li><a title="El evento PageIndexChanging" href="http://adeshoras.wordpress.com/2008/08/15/el-gridview-y-sus-eventos-el-evento-pageindexchanging/" target="_blank">El GridView y sus eventos: El evento PageIndexChanging</a>.</li>
<li><a title="El evento Sorting) en A deshoras" href="http://adeshoras.wordpress.com/2008/08/27/ordenando-un-gridview-mediante-el-evento-sorting-el-gridview-y-sus-eventos-el-evento-sorting/" target="_blank">Ordenando un GridView mediante el evento Sorting (El GridView y sus eventos: El evento Sorting)</a>.</li>
</ul>
<h3>Descargas - Downloads.</h3>
<ul>
<li><a title="//adeshoras.wordpress.com/" href="http://cid-4aa6af1b4a447319.skydrive.live.com/self.aspx/a-deshoras-aplicaciones-y-codigos-de-ejemplo/GridViewEventsSolution.zip" target="_blank">Descargate el código de ejemplo usado en este post y seguro que así puedes comprender mejor como funciona el evento RowDataBound.</a></li>
</ul>
<p>Mientras he escrito este post he estado escuchando el fabuloso Odelay de Beck, así que aqui os dejo con él. Que lo disfruteis.</p>
<p><span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='http://www.youtube.com/v/GROZm6wqshk'></param><param name='wmode' value='transparent'></param><embed src='http://www.youtube.com/v/GROZm6wqshk&rel=0' type='application/x-shockwave-flash' wmode='transparent' width='425' height='350'></embed></object></span></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Show no data to display message when gridview is empty ]]></title>
<link>http://sujitkumar.wordpress.com/?p=23</link>
<pubDate>Thu, 14 Aug 2008 08:22:37 +0000</pubDate>
<dc:creator>sujitkumar21</dc:creator>
<guid>http://sujitkumar.it.wordpress.com/2008/08/14/show-message-when-gridview-is-empty/</guid>
<description><![CDATA[Show Message when Gridview is empty
there is 2 method to show message when gridview is empty

settin]]></description>
<content:encoded><![CDATA[<p>Show Message when Gridview is empty</p>
<p>there is 2 method to show message when gridview is empty</p>
<li>
<p>setting ShowHeaderWhenEmpty="true" EmptyDataText="No records found" property of gridview</p>
</li>
<li>
<p> using EmptyDataTemplate column of gridview
</p>
</li>
]]></content:encoded>
</item>
<item>
<title><![CDATA[GridView with paging and sorting and LINQ]]></title>
<link>http://psinke.wordpress.com/?p=12</link>
<pubDate>Tue, 12 Aug 2008 16:32:36 +0000</pubDate>
<dc:creator>psinke</dc:creator>
<guid>http://psinke.it.wordpress.com/2008/08/12/gridview-with-paging-and-sorting-and-linq/</guid>
<description><![CDATA[After a couple of hours researching I finally got it to work, a GridView that gets it&#8217;s dtat t]]></description>
<content:encoded><![CDATA[<p>After a couple of hours researching I finally got it to work, a GridView that gets it's dtat through LINQ and has paging and sorting enabled. At first i tried to do things the hard way (ofcourse) and couple data to the grid by setting the datasource to the IQueryable resutl from a LINQ query. While this works fine, it's a bit of a bitch to get sorting and pagina to work that way. I got to a point where I had paging and sorting working, but when I switched pages the sorting was lost and vice versa. Then I tried a little something with storing the result in the Session object after every page or sort change, but while that worked, it didn't feel right, and by the time this was working the amount of code was getting to be too much.</p>
<p>So, back to Google. Then I came across an article by <a href="http://weblogs.asp.net/scottgu/archive/2007/07/16/linq-to-sql-part-5-binding-ui-using-the-asp-linqdatasource-control.aspx" target="_self">Scott Guthrie</a> which explains the coupling of a LinqDataSource to a GridView. An excellent article. By doing the steps described there I was able to couple my DataContext to the Grid, select the needed table and columns and enable sorting and paging without writing a single line of code.</p>
<p>Here's a shot of the final result:</p>
<p><a href="http://www.grabout.com/Default.aspx?i=796c3bd6-6f5f-4cda-9dcc-bf5f85c34bf3" target="_self">http://www.grabout.com/Default.aspx?i=796c3bd6-6f5f-4cda-9dcc-bf5f85c34bf3</a></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Colored ASP.NET GridView Cells]]></title>
<link>http://adrianhenke.wordpress.com/?p=46</link>
<pubDate>Mon, 11 Aug 2008 15:30:09 +0000</pubDate>
<dc:creator>adrianhenke</dc:creator>
<guid>http://adrianhenke.it.wordpress.com/2008/08/11/colorize-aspnet-gridview-cells/</guid>
<description><![CDATA[In Excel, there is a useful feature that lets you change the color of a cell depending on its value.]]></description>
<content:encoded><![CDATA[<p>In Excel, there is a useful feature that lets you change the color of a cell depending on its value. As example, you could make a "total money" cell show up with a red background if its value is below zero. How can we do this with ASP.NET gridviews? There is no built-in functionality to make this work, you'll need to write a few lines of code to get this done. Here is how I would solve this issue: Subscribe to the <em>RowDataBound</em> Event of your gridview, it is fired when the current row has been bound to data (filled with values):</p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:#2b91af;">GridView</span><span style="font-size:8pt;font-family:&#34;"> gv = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">GridView</span>();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;">gv.RowDataBound += <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">GridViewRowEventHandler</span>(gv_RowDataBound);</span></p>
<p><span>In the according event handler, iterate through all cells and update their background-color based on their </span><span>value:</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:green;font-family:&#34;" lang="EN-US">// color last cell</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&#34;" lang="EN-US">void</span><span style="font-size:8pt;font-family:&#34;" lang="EN-US"> gv_RowDataBound(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">GridViewRowEventArgs</span> e)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US"><span>    </span><span style="color:blue;">if</span> (e.Row.RowType == <span style="color:#2b91af;">DataControlRowType</span>.DataRow)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US"><span>        </span><span style="color:blue;">if</span> (e.Row.Cells.Count &#62; 0)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US"><span>            </span><span style="color:#2b91af;">TableCell</span> c = e.Row.Cells[e.Row.Cells.Count - 1];</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US"><span>            </span><span style="color:blue;">if</span> (!<span style="color:blue;">string</span>.IsNullOrEmpty(c.Text))</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US"><span>            </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US"><span>                </span><span style="color:blue;">try</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US"><span>                </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US"><span>                    </span><span style="color:blue;">int</span> value = <span style="color:blue;">int</span>.Parse(c.Text);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US"><span>                    </span>c.BackColor =</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US"><span>                        </span>value &#62;= 100 ? <span style="color:#2b91af;">Color</span>.LimeGreen :</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US"><span>                        </span>value &#62;= 85 ? <span style="color:#2b91af;">Color</span>.Gold :</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US"><span>                        </span><span style="color:#2b91af;">Color</span>.IndianRed;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US"><span>                    </span>c.Text = <span style="color:blue;">string</span>.Format(<span style="color:#a31515;">"{0}%"</span>, value); <span style="color:green;">// add percentage sign</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;" lang="EN-US"><span>                </span></span><span style="font-size:8pt;font-family:&#34;">}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;"><span>                </span><span style="color:blue;">catch</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;"><span>                </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;"><span>                    </span>c.Text = <span style="color:blue;">null</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;"><span>                </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;"><span>            </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&#34;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:8pt;line-height:115%;font-family:&#34;">}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;">
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span>Done...</span></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[El GridView y sus eventos: El RowDataBound]]></title>
<link>http://adeshoras.wordpress.com/?p=99</link>
<pubDate>Sat, 09 Aug 2008 19:31:25 +0000</pubDate>
<dc:creator>César</dc:creator>
<guid>http://adeshoras.it.wordpress.com/2008/08/09/el-gridview-y-sus-eventos-el-evento-rowdatabound/</guid>
<description><![CDATA[En este post, vamos a ver el evento (seguramente el más usado), el RowDataBound. Vamos a ver cuando]]></description>
<content:encoded><![CDATA[<p>En este post, vamos a ver el evento (seguramente el más usado), el RowDataBound. Vamos a ver cuando se ejecuta, cual es su finalidad y lo que nos aporta.</p>
<p>El GridView es un control que nos proporciona ASP.NET cuya funcionalidad es “trabajar” con información tabular. Seguramente es uno de los controles más usados y a lo lardo de las distintas versiones de Visual Estudio, ha cambiado el nombre, pero siempre se ha mantenido. Este control, es muy pesado y consume gran cantidad de memoria pero aporta mucha funcionalidad que muchas veces no llegamos a aprovechar porque generalmente lo usamos para mostrar información (entendamos que hablo de aplicaciones Web).</p>
<p>Este post forma parte de una serie de post llamada El GridView y sus Eventos. Los post que forman esta serie y que si has llegado aquí te pueden interesar son:</p>
<ul>
<li><a title="//adeshoras.wordpress.com/" href="http://adeshoras.wordpress.com/2008/08/09/el-gridview-y-sus-eventos-el-evento-rowdatabound/" target="_blank">El GridView y sus eventos: El evento RowDataBound</a>.</li>
<li><a title="El evento PageIndexChanging" href="http://adeshoras.wordpress.com/2008/08/15/el-gridview-y-sus-eventos-el-evento-pageindexchanging/" target="_blank">El GridView y sus eventos: El evento PageIndexChanging</a>.</li>
<li><a title="El evento Sorting) en A deshoras" href="http://adeshoras.wordpress.com/2008/08/27/ordenando-un-gridview-mediante-el-evento-sorting-el-gridview-y-sus-eventos-el-evento-sorting/" target="_blank">Ordenando un GridView mediante el evento Sorting (El GridView y sus eventos: El evento Sorting)</a>.</li>
</ul>
<h3>El evento RowDataBound</h3>
<p>El evento RowDataBound, se levanta cada vez que un DataItem es bindado. Es decir, cada vez que se vaya a enlazar información de nuestra fuente de datos a una fila del GridView este evento salta.</p>
<p>Este evento es tremendamente útil cuando sea necesario modificar la información que le vamos a mostrar al usuario.</p>
<p>Imaginar que queremos formatear una fecha, o sustituir por imágenes (ok, ko etc.) un campo que nos marque un estado, pues sería por medio de este evento donde lo haríamos.<!--more--></p>
<p>Una implementación sencilla de este evento, tendría el siguiente aspecto:</p>
<p><code>protected void GvCountries_RowDataBound(object sender, GridViewRowEventArgs e)<br />
{<br />
if (e.Row.RowType == DataControlRowType.DataRow)<br />
{<br />
Country country = (Country) e.Row.DataItem;<br />
Literal l = (Literal)e.Row.FindControl("ltrlName");<br />
if (l != null) l.Text = country.Name;<br />
}<br />
}</code></p>
<p>Como veis, es sencillo, cada vez que salta comprobamos el tipo de row que nos viene y operamos, yo en mi caso unicamente le asigno un valor a un literal.</p>
<p>Para enlazar el evento al control, tenemos que hacerlo de la siguiente forma:</p>
<p><code>&#60;asp:GridView<br />
ID="gvCountries"<br />
runat="server"<br />
DataKeyNames="CountryCode"<br />
CssClass="cssTableGrid"<br />
AutoGenerateColumns="False"<br />
OnRowDataBound="GvCountries_RowDataBound"&#62;&#60;/asp:GridView&#62;</code></p>
<p>Y si tambien quieres hacerlo programáticamente sería asi:</p>
<p><code>gvCountries.RowDataBound += new GridViewRowEventHandler(gvCountries_RowDataBound);</code></p>
<p>Esto no tiene más. Facil verdad, pues si, pero a lo largo de estos post, veremos que con un GridView y algunos de sus eventos implementados y ademas un poquito de Ajax vamos a conseguir unos resultados espectaculares que a más de uno le dejaran con la boca abierta (sobre todo por lo usable que va a ser el asunto)</p>
<h3>Post relacionados.</h3>
<p>Este post forma parte de una serie de post llamada El GridView y sus Eventos. Los post que forman esta serie y que si has llegado aquí te pueden interesar son:</p>
<ul>
<li><a title="//adeshoras.wordpress.com/" href="http://adeshoras.wordpress.com/2008/08/09/el-gridview-y-sus-eventos-el-evento-rowdatabound/" target="_blank">El GridView y sus eventos: El evento RowDataBound</a>.</li>
<li><a title="El evento PageIndexChanging" href="http://adeshoras.wordpress.com/2008/08/15/el-gridview-y-sus-eventos-el-evento-pageindexchanging/" target="_blank">El GridView y sus eventos: El evento PageIndexChanging</a>.</li>
<li><a title="El evento Sorting) en A deshoras" href="http://adeshoras.wordpress.com/2008/08/27/ordenando-un-gridview-mediante-el-evento-sorting-el-gridview-y-sus-eventos-el-evento-sorting/" target="_blank">Ordenando un GridView mediante el evento Sorting (El GridView y sus eventos: El evento Sorting)</a>.</li>
</ul>
<h3>Descargas - Downloads</h3>
<ul>
<li><a title="//adeshoras.wordpress.com/" href="http://cid-4aa6af1b4a447319.skydrive.live.com/self.aspx/a-deshoras-aplicaciones-y-codigos-de-ejemplo/GridViewEventsSolution.zip" target="_blank">Descargate el código de ejemplo usado en este post y seguro que así puedes comprender mejor como funciona el evento RowDataBound.</a></li>
</ul>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Update Bulk Data Using GridView]]></title>
<link>http://sujitkumar.wordpress.com/?p=17</link>
<pubDate>Thu, 07 Aug 2008 06:31:33 +0000</pubDate>
<dc:creator>sujitkumar21</dc:creator>
<guid>http://sujitkumar.it.wordpress.com/2008/08/07/update-bulk-data-using-gridview/</guid>
<description><![CDATA[In this post I am updating bulk data at a time using gridview with maintaing transaction.
below cont]]></description>
<content:encoded><![CDATA[<p>In this post I am updating bulk data at a time using gridview with maintaing transaction.</p>
<p>below controls are under gridview template column.</p>
<p>&#60;asp:Label ID="lblID" runat="server" Text='' Width="30px"&#62;</p>
<p>&#60;asp:Label ID="txtFaults" runat="server" Text='' Width="200px"&#62;</p>
<p>&#60;asp:DropDownList CssClass="dropdown" ID="ddlRepair" runat="server" Width="100px" SelectedValue=''&#62;</p>
<p>&#60;asp:TextBox CssClass="textbox" ID="txtRepairedRemarks" runat="server" Text='' Width="180px"&#62;</p>
<p>-----------------------------------------------------------<br />
DataTable objDt = new DataTable();<br />
SqlDataAdapter objAdapter;<br />
SqlConnection cnn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["con"].ToString());<br />
SqlCommand cmd = new SqlCommand();</p>
<p>//Get values in GridView</p>
<p>  cmd = new SqlCommand("SP_Name", cnn);</p>
<p>        cmd.CommandType = CommandType.StoredProcedure;</p>
<p>        cmd.Parameters.Add("@Parm", SqlDbType.Int).Value = 12;</p>
<p>        objAdapter = new SqlDataAdapter(cmd,cnn);</p>
<p>        objAdapter.Fill(objDt);</p>
<p>        gv.DataSource = objDt;<br />
        gv.DataBind();</p>
<p>//code to update data in database</p>
<p>private void BeginToUpdate()<br />
    {<br />
        cnn.Open();<br />
        SqlTransaction tran = cnn.BeginTransaction();<br />
        cmd.Connection = cnn;<br />
        cmd.Transaction = tran;<br />
        cmd.CommandText = " UPDATE FAULTS SET REPAIRED=@parm WHERE FAULT_ID=@id";<br />
        SqlParameter p1 = new SqlParameter("@parm", SqlDbType.VarChar);<br />
  SqlParameter p2 = new SqlParameter("@id", SqlDbType.Int);<br />
        cmd.Parameters.Add(p1);<br />
  cmd.Parameters.Add(p2);</p>
<p>    }</p>
<p>    private void CompleteToUpdate()<br />
    {<br />
        try<br />
        {<br />
            cmd.Transaction.Commit();<br />
        }<br />
        catch (Exception ex)<br />
        {<br />
            //show error<br />
        }<br />
        finally<br />
        {<br />
            cnn.Close();<br />
        }<br />
    }</p>
<p>    private void UpdateData(string repaired, Int32 id)<br />
    {<br />
        try<br />
        {<br />
            cmd.Parameters[0].Value = Convert.ToChar(repaired);<br />
cmd.Parameters[1].Value = Convert.ToChar(id);<br />
            cmd.ExecuteNonQuery();<br />
        }<br />
        catch<br />
        {<br />
            cmd.Transaction.Rollback();<br />
        }<br />
    }</p>
<p>//write this under save/update button onClick event</p>
<p>BeginToUpdate();<br />
        foreach (GridViewRow row in gv.Rows)<br />
        {<br />
            if (row.RowType == DataControlRowType.DataRow)<br />
            {<br />
Int32 id = Convert.ToInt32(((Label)row.FindControl("lblid")).Text);<br />
                string repaired = ((DropDownList)row.FindControl("ddlRepair")).SelectedValue.ToString();</p>
<p>                if (id &#62; 0 &#38;&#38; repaired=="R")<br />
                {<br />
                    UpdateData(repaired,id);<br />
                }<br />
            }<br />
        }</p>
<p>        CompleteToUpdate();</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Un solo RowDataBound para varias GridView]]></title>
<link>http://trytocatch.wordpress.com/2008/07/28/un-solo-rowdatabound-para-varias-gridview/</link>
<pubDate>Mon, 28 Jul 2008 20:09:39 +0000</pubDate>
<dc:creator>Fernando Sanchez</dc:creator>
<guid>http://trytocatch.it.wordpress.com/2008/07/28/un-solo-rowdatabound-para-varias-gridview/</guid>
<description><![CDATA[Suele pasar que tengamos mas de una grilla (gridView en .NET 2.0) en una misma pagina Web y es incom]]></description>
<content:encoded><![CDATA[<p>Suele pasar que tengamos mas de una grilla (gridView en .NET 2.0) en una misma pagina Web y es incomodo, cuando se necesita que cada fila tenga un comportamiento, copiar y pegar código para cada grilla en el evento RowDataBound. Por ejemplo, si quiero a cada fila agregarle algo de Javascript para su validación o simplemente cambiar de color esa fila.</p>
<p>Este ejemplo muetra como enlazar un solo evento RowDataBound para las grillas que sean necesarias en un misma pagina. Esta hecho en  ASP.NET (VB.NET) 2.0</p>
<p>Una vez creado el proyecto y agregada las 2 GridView, simplemente en el Code Behind y nos paramos sobre una GridView.</p>
<p><a href="http://trytocatch.files.wordpress.com/2008/07/foto0.jpg"><img style="border-width:0;" src="http://trytocatch.files.wordpress.com/2008/07/foto0-thumb.jpg" border="0" alt="foto0" width="421" height="145" /></a></p>
<p>Y luego en sus eventos vamos al RowDataBound:</p>
<p><a href="http://trytocatch.files.wordpress.com/2008/07/foto01.jpg"><img style="border-width:0;" src="http://trytocatch.files.wordpress.com/2008/07/foto01-thumb.jpg" border="0" alt="foto01" width="363" height="401" /></a></p>
<p>Una vez que nos genero el código simplemente vamos hacia el handles (que esta al final) con comas vamos agregando todos los objetos que queremos que ese evento maneje:</p>
<p><a href="http://trytocatch.files.wordpress.com/2008/07/foto1.jpg"><img style="border-width:0;" src="http://trytocatch.files.wordpress.com/2008/07/foto1-thumb.jpg" border="0" alt="foto1" width="386" height="156" /></a></p>
<p>Ahora bien, la pregunta es simple: ¿Como distingo una Grilla de Otra?, simple:</p>
<pre style="border:1px solid gainsboro;overflow:auto;font-size:8pt;background-image:none;width:90.91%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;height:304px;background-color:#f4f4f4;margin:0;padding:5px;">
<div>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">Protected</span> <span style="color:#0000ff;">Sub</span> GridView1_RowDataBound(<span style="color:#0000ff;">ByVal</span> sender <span style="color:#0000ff;">As</span> <span style="color:#0000ff;">Object</span>, <span style="color:#0000ff;">ByVal</span> e <span style="color:#0000ff;">As</span> System.Web.UI.WebControls.GridViewRowEventArgs) _
                   <span style="color:#0000ff;">Handles</span> GridView1.RowDataBound, GridView2.RowDataBound

       <span style="color:#0000ff;">If</span> e.Row.RowType = DataControlRowType.DataRow <span style="color:#0000ff;">Then</span> <span style="color:#008000;">'DataRow Vale las row que tienen datos, de esta manera se saltea el header,el footer y el pager</span>
           <span style="color:#0000ff;">Dim</span> idCelda <span style="color:#0000ff;">As</span> <span style="color:#0000ff;">Integer</span>
           <span style="color:#0000ff;">Dim</span> gvrow <span style="color:#0000ff;">As</span> GridViewRow = <span style="color:#0000ff;">CType</span>(e.Row.Cells(idCelda).NamingContainer, GridViewRow)
           <span style="color:#0000ff;">Select</span> <span style="color:#0000ff;">Case</span> <span style="color:#0000ff;">CType</span>(sender, GridView).ID
               <span style="color:#0000ff;">Case</span> GridView1.ID
                   gvrow.BackColor = Drawing.Color.Red
               <span style="color:#0000ff;">Case</span> GridView2.ID
                   gvrow.BackColor = Drawing.Color.LightGoldenrodYellow
           <span style="color:#0000ff;">End</span> <span style="color:#0000ff;">Select</span>
       <span style="color:#0000ff;">End</span> <span style="color:#0000ff;">If</span>

   <span style="color:#0000ff;">End</span> Sub</pre>
</div>
</pre>
<p>Bastante sencillo. Y así es como nos queda:</p>
<p><a href="http://trytocatch.files.wordpress.com/2008/07/fotofinal.jpg"><img style="border-width:0;" src="http://trytocatch.files.wordpress.com/2008/07/fotofinal-thumb.jpg" border="0" alt="fotofinal" width="244" height="178" /></a></p>
<p>Adjunto el proyecto <a href="http://rapidshare.com/files/133153377/ManejarEventoRowDataBound.rar" target="_blank">aqui</a></p>
<p>Saludos.</p>
]]></content:encoded>
</item>

</channel>
</rss>
