Asp.net programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this Asp.net and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Asp.net Website by URL, How to Play YouTube Videos in Asp.net by using Jquery , Jquery Change div background on mouseover in asp.net , JQuery UI Datepicker (Calendar) etc.

Thursday, February 19, 2015

How to bind asp datalist control dynamically in asp.net

How to bind asp datalist control dynamically in asp.net:




in this post  we are try  discuss how we can implement this application that displays the employee details, like code, name, and the individual's photo. We need an Image control that we will use inside the ItemTemplate of the DataList control in use. Here is how you can use the Image control.


ItemTemplate of the DataList :


<img src='<# DataBinder.Eval(Container.DataItem, "EmpName") %>.png' style="height:100px;width:100px;border:1px solid gray;"/>
Note that all the images have a primary name corresponding to the employee's name with a .png extension. The complete source code of the DataList control in your .aspx fi le would be similar to what follows: 
<asp:DataList ID="DataList1" runat="server" RepeatColumns="2" RepeatDirection="Horizontal">
                  <ItemTemplate>
                             <table id="Table1" cellpadding="1" cellspacing="1" visible ="true">
                                    <tr>
                                            <td width="50px">
                                            <p align="left">
                                                  <asp:Label ID="lblEmpCode" runat ="server" CssClass="LabelStyle" Text='
                                                           <%# DataBinder.Eval(Container.DataItem, "EmpCode")%>'>
                                            </p>
                                            <td>
                                            <td width="200px">
                                            <p align="left">
                                                      <asp:Label ID="lblEmpName" runat = "server"< BR >                                                            CssClass="LabelStyle" Text='
                                                            <%# DataBinder.Eval(Container.DataItem, "EmpName")%>'>
                                                      </asp:Label>
                                            </p>
                                            </td>
                                            <td width="100px">
                                            <p align="left">
                                                      <img src= '<%#DataBinder.Eval(Container.DataItem, < BR>                                                                   "EmpName") %>.png'
                                                                  style="height:100px;width:100px;border:1px solid gray;"/>
                                             </td>
                                             </p>
                                             </td>
                            </table>
                       </ItemTemplate>
</asp:DataList>


Note the use of the properties RepeatColumns and RepeatDirection in this code snippet. While the former implies the number of columns that you would like to display per record in the rendered output, the later implies the direction of the rendered output, that is, horizontal or vertical.


Other Related Post :


No comments:

Post a Comment