change item template in ASP.NET grid view related to fields value

901 views Asked by At

i have a grid view to show my blog posts, my posts are in video,image,text format and each has html template that is different with another:

html:

<!-- Image Format -->
        <div class="post format-image box"> 
            <div class="frame">
                <a href="post.html">
                    <img src="Templates/images/art/post1.jpg" alt="" />
                </a>
            </div>
            <h2 class="title"><a href="post.html">Morning Glory</a></h2>
            <p>text</p>
            <div class="details">
                <span class="icon-image"><a href="#">September 26, 2012</a></span>
                <span class="likes"><a href="#" class="likeThis">44</a></span>
                <span class="comments"><a href="#">3</a></span>
            </div>
        </div>

<!-- Video Format -->
        <div class="post format-video box"> 
            <div class="video frame">
            <iframe src="http://player.vimeo.com/video/40558553?title=0&byline=0&portrait=0" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
            </div>
            <h2 class="title"><a href="post.html">Fragments of Iceland</a></h2>
            <p>text</p>

            <div class="details">
                <span class="icon-video"><a href="#">September 13, 2012</a></span>
                <span class="likes"><a href="#" class="likeThis">18</a></span>
                <span class="comments"><a href="#">1</a></span>
            </div>

        </div>


<!-- Text Format -->
        <div class="post format-standard box"> 

            <h2 class="title"><a href="post.html">The Meridian Sun</a></h2>
            <p>text</p>
    <p>text</p>

            <div class="details">
                <span class="icon-standard"><a href="#">August 13, 2012</a></span>
                <span class="likes"><a href="#" class="likeThis">11</a></span>
                <span class="comments"><a href="#">0</a></span>
            </div>

        </div>

as you know if i want to have list of my posts in usually way i should add grid view with item template and set my template in it, but as you see i have 3 templates for my records, and i have a field in my table called 'PostMode' that accepts 3 string : Video, Image, Text. now my question is how can i use 3 templates in item template that if my record was Video display video template and if it was Text display Text format in my blogs list.

1

There are 1 answers

2
Suraj Singh On
 TemplateField tF = new TemplateField();
                    // tF.HeaderText = dr["COLUMN_NAME"].ToString();
                    tF.HeaderText = col.ToString();
                    tF.ItemTemplate = LoadTemplate("~/xxxxxxx.ascx");
                    grdVw.Columns.Add(tF);

Sorry for posting in such a hurry ,

Hope it helps .