Monday, April 2, 2012

Using Datalist in asp.net

 .aspx.

<asp:DataList id="dlpoolers" runat="server"   CellPadding="0" RepeatDirection="Horizontal" RepeatColumns="4"  CellSpacing="0" Width='100%'>
      <ItemTemplate>           
          &nbsp; <asp:Label ID="lblcid" runat="server" Text='<%#Eval("iCId")%>' Visible="false" align="center"></asp:Label>
          <asp:Label ID="lblphotopaths" runat="server" Text='<%#Eval("vPhotoPath")%>' Visible="false"></asp:Label>
          <asp:Label ID="lblphoto1" runat="server"></asp:Label>
          <asp:Label ID="lblname" Text='<%#Eval("vName")%>' runat="server"></asp:Label>
  <hr />
</ItemTemplate>
</asp:DataList>

.aspx.cs
protected void dlview_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if ((e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem))
        {
            try
            {
                string path1 = "";
                string name = "";
                string links = "";
                string strfname = "";
                string strlname = "";
                string straddr = "";
                Label lbllinks = e.Item.FindControl("lblcpownerid") as Label;
                links = lbllinks.Text;
               
                // fist image
                Label lblpath1 = e.Item.FindControl("lblphotopath") as Label;
                path1 = lblpath1.Text;
                Label lblphoto = e.Item.FindControl("lblphoto") as Label;
               
                if (path1 != "")
                {
                  
                    lblphoto.Text = "<b><a href='#'><img src='" + sAppDomain + "/" + path1 + "' height='120' width='120' border='0' /></a></b>";
                    lblphoto.Attributes.Add("OnClick", "getphotos('" + links + "');");
                }
                else
                {

                    lblphoto.Text = "<b><a href='#'><img src='" + Application["Root"] + "Images/nopic.png' height='120' width='120' border='0' /></a></b>";
                    lblphoto.Attributes.Add("OnClick", "getphotos('" + links + "');");                                  }
                // end of first image              

            }
            catch (Exception ex)
            {
                string s = ex.Message.ToString();
            }      

        }
    }

No comments:

Post a Comment

Comments

Protected by Copyscape Plagiarism Software