Sanal.org
till 01th May 2006
Categories
.NET (40)
Art (1)
Blogs (1)
Computers (6)
Information (13)
Internet (11)
Movies (5)
Music (19)
MY SQL (5)
People (16)
Russian (20)
Security (15)
SEO (3)
SQL SERVER (8)
Technology (6)
Turkey (2)
Video (7)
More
TOP 50
Turkish News


Archive
April (2008)
March (2008)
February (2008)
January (2008)
December (2007)
Novamber (2007)
October (2007)
September (2007)
August (2007)
July (2007)
June (2007)
May (2007)
April (2007)
March (2007)
February (2007)
January (2007)
December (2006)
Novamber (2006)
October (2006)
September (2006)
August (2006)
July (2006)
June (2006)
May (2006)
April (2006)
March (2006)
February (2006)
January (2006)
December (2005)
October (2005)
April (2005)
December (1969)

32

ROR
Previous123Next

Taming DataList With a Custom Adapter


Suppose you want to extend a DataList and have it put out a div for each row. The RepeatLayout property can be either Flow (“Items are displayed without a table structure”) or Table (“Items are displayed in a table”). Since we want divs, we’re after RepeatLayout = RepeatLayout.Flow. Not so fast, though. This control isn’t that easy to extend.

What you get is a <span> which wraps the rest of the markup. More so, <div> rows are separated with superfluous <br>s that come out of nowhere!

<span id="foo">
    <div class="bar"></div>
    <br>
    <div class="bar"></div>
    <br>
    <div class="bar"></div>
    <br>
</span>

The first impulse is to override the TagKey property:

protected override HtmlTextWriterTag TagKey
{
  get { return HtmlTextWriterTag.Div; }
}

Just about every control will yield and render what you tell it, but not DataList. Beat your head against the wall—you still get a <span>. How weird is it to have an inline element wrap a block element!

My next guess was to look inside the ASP.NET CSS Friendly Control Adapters, but I was in for a disappointment. The DataListAdapter does not accommodate the “flow” layout. It merely produces a cleaner <table>. Back to the drawing board.

Eventually, I wrote my own, simple adapter:

namespace MyNamespace
{
  public class MyListControlAdapter : WebControlAdapter
  {
    protected override void RenderContents (HtmlTextWriter w)
    {
       DataList dataList = Control as DataList;

       if (dataList != null)
       {
          foreach (DataListItem li in dataList.Items)
              li.RenderControl (w);
       }
       else
       {
          base.RenderContents (w);
       }
    }
  }
}

which produced pristine markup:

<div id="foo">
   <div class="bar"></div>
   <div class="bar"></div>
   <div class="bar"></div>
</div>

Remember to create, or edit, a file named default.browser in the App_Browsers folder and add the following section:

<browsers>
  <browser refID="Default">
    <controlAdapters>
    <adapter
      controlType="MyNamespace.MyListControl"
      adapterType="MyNamespace.MyListControlAdapter" />
    </controlAdapters>
  </browser>
</browsers>

Hope this tip saves someone a day or two of head beating.




Fantastic Mirrors by Ayhan Tomak


*TNCS*


One Good Use of Silverlight


I talked about my frustration with Silverlight to a couple of people at the recent tri-state community mixer and heard the same thing several times: “I wish I could come up with a project to try Silverlight.” This goes to reinforce my opinion that Silverlight is being pitched to the wrong audience (developers) with the wrong message (“Rich media experience for the masses”).

sIFR + Silverlight

If you’ve followed this blog for a while, you may remember .IR — an image replacement technique I derived from sFIR which allowed you to embed Flash with an arbitrary font in place of plain vanilla Arial/Helvetica/Verdana headings. Instead of Flash I used an image-streaming HttpHandler that utilized GDI+. Maximilian Beller even created a server control out of .IR, and Carl Camera kicked it up a notch and came up with ViPR.

Back then I left .IR in beta even though I’ve used it on this site (view this page in a browser to see for yourselves) ever since. I’ve grown sick of endless betas since then. If I put out anything these days, it’s at least ver. 1.0.

It occurred to me that the same technique should be doable and even more flexible with Silverlight. Not surprisingly, it’s already in the works! Filipe Fortes seems to be working on Sistr (sIFR + Silverlight) which you can see in action here. Good stuff! Gotta keep an eye on this development.



Previous123Next

0.015625
Bilgi Portalı | Forum | Haberler | Havacılık | Daily News | Noticias