Open a SharePoint team site.

SharePoint team site

Create a Custom list for binding a data into repeater control.

Custom list

So now the list has been created successfully. Create some custom columns into the list.

Create some custom columns into the list

Create a document library for storing ‘Product’ Images and insert some images into the library.

Create a document library

Now open our product list and insert some products into it.

Provide the product image URL from Products images library.

product

Open Visual studio, create a new SharePoint 2013 empty project and Add a visual webpart into it.

Use CAML Query to retrieve the server code.

CAML Query

Code

ASPX Code

  1. <div style="height:300px; width:400px">
  2. <table style="width:100%">
  3. <tr>
  4. <td style="width:10%"></td>
  5. <td style="width:80%">
  6. <div class="rptprods" style="padding-right: 20px; height:150px; width:200px;">
  7. <asp:Repeater ID="rptprod" runat="server">
  8. <ItemTemplate>
  9. <img src="<%#DataBinder.Eval(Container.DataItem," Image ") %>" width="200" height="200" />
  10. <br />
  11. <h2 style="padding-top: 5px; font-weight: bold; font-size: 10px;"><%#DataBinder.Eval(Container.DataItem,"Title") %></h2>
  12. <br />
  13. <b> Availablity:</b>
  14. <p style="color:green;">
  15. <%#DataBinder.Eval(Container.DataItem,"Available") %>
  16. </p>
  17. <br />
  18. <b> Price:</b>
  19. <p style="color:green;">
  20. <%#DataBinder.Eval(Container.DataItem,"Price") %>
  21. </p>
  22. <hr />
  23. </ItemTemplate>
  24. </asp:Repeater>
  25. </div>
  26. </td>
  27. <td style="width:10%"></td>
  28. </tr>
  29. </table>
  30. </div>
CS Code
  1. using Microsoft.SharePoint;
  2. using System;
  3. using System.ComponentModel;
  4. using System.Web.UI;
  5. using System.Web.UI.WebControls.WebParts;
  6. namespace Rollup_announcement.annao2
  7. {
  8. [ToolboxItemAttribute(false)]
  9. public partial class annao2 : WebPart
  10. {
  11. public annao2()
  12. {
  13. }
  14. protected override void OnInit(EventArgs e)
  15. {
  16. base.OnInit(e);
  17. InitializeControl();
  18. }
  19. protected void Page_Load(object sender, EventArgs e)
  20. {
  21. if (!Page.IsPostBack)
  22. {
  23. Bindspeaker();
  24. }
  25. }
  26. private void Bindspeaker()
  27. {
  28. using (SPSite site = new SPSite(SPContext.Current.Site.Url))
  29. {
  30. using (SPWeb web = site.OpenWeb())
  31. {
  32. SPList list = web.Lists["Our Products"];
  33. if (list != null)
  34. {
  35. SPQuery query = new SPQuery();
  36. query.Query = "<Where><Eq><FieldRef Name='Active' /><Value Type='Boolean'>1</Value></Eq></Where>";
  37. SPListItemCollection collitem = list.GetItems(query);
  38. if (collitem != null)
  39. {
  40. rptprod.DataSource = collitem.GetDataTable();
  41. rptprod.DataBind();
  42. }
  43. }
  44. }
  45. }
  46. }
  47. }
  48. }
Final Result

Final Result

Happy SharePoint!