Repeater Control
-
Tuesday, August 07, 2012 6:46 AM
Hi,
I need to use Repeater control to display multiple data including attributes fetched from CRM. I donot have a data source or an xml file than how can I bind data in repeater control.
Please help.
Thanks
All Replies
-
Tuesday, August 07, 2012 3:14 PM
you could use DataTable instead of xml.
I think you will get some idea from the below code
In my last project i have implement the same but with the incident entity.
public DataTable viewMyCases() { try { DataTable dt = new DataTable(); dt.Columns.Add("Title"); dt.Columns.Add("Case Number"); dt.Columns.Add("Priority"); dt.Columns.Add("Created On"); dt.Columns.Add("linkAddNotes"); dt.Columns.Add("Case Origin"); dt.Columns.Add("Status Reason"); dt.Columns.Add("Owner"); credentials.UserName.UserName = ConfigurationManager.AppSettings["username"]; credentials.UserName.Password = ConfigurationManager.AppSettings["userPassword"]; deviceCredentials.UserName.UserName = ConfigurationManager.AppSettings["dusername"]; deviceCredentials.UserName.Password = ConfigurationManager.AppSettings["duserid"]; organizationUri = new Uri(ConfigurationManager.AppSettings["orgurl"]); homeRealmUri = null; using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, deviceCredentials)) { IOrganizationService service = (IOrganizationService)serviceProxy; QueryExpression query = new QueryExpression("incident"); query.ColumnSet.AddColumns("incidentid", "title", "statecode", "ticketnumber", "prioritycode", "createdon", "caseorigincode", "statuscode", "ownerid"); EntityCollection result1 = service.RetrieveMultiple(query); foreach (var a in result1.Entities) { DataRow dr = dt.NewRow(); //DataRow dr = new DataRow(); if (a.Attributes.Contains("title")) { dr["Title"] = a.Attributes["title"].ToString(); } if (a.Attributes.Contains("ticketnumber")) { dr["Case Number"] = a.Attributes["ticketnumber"].ToString(); } if (a.Attributes.Contains("prioritycode")) { dr["Priority"] = a.FormattedValues["prioritycode"]; } if (a.Attributes.Contains("createdon")) { dr["Created On"] = a.Attributes["createdon"].ToString(); } dr["linkAddNotes"] = "selectedCase.aspx?incidentid=" + a.Attributes["incidentid"].ToString(); if (a.Attributes.Contains("caseorigincode")) { dr["Case Origin"] = a.FormattedValues["caseorigincode"]; } if (a.Attributes.Contains("statuscode")) { dr["Status Reason"] = a.FormattedValues["statuscode"]; } if (a.Attributes.Contains("ownerid")) { EntityReference ownerName = (EntityReference)a.Attributes["ownerid"]; //string managingparter = ownerName.Name; dr["Owner"] = ownerName.Name; } dt.Rows.Add(dr); } } return dt; } catch (System.Exception excep) { DataTable dt = new DataTable(); return dt; } }Your repeater should look like the below code
<asp:Repeater runat="server" id="Repeater1"> <itemtemplate> <b><%# DataBinder.Eval(Container.DataItem, "Title") %></b> <br> </itemtemplate> <separatortemplate> <hr> </separatortemplate> </asp:Repeater>This is just a sample code if you need any information please let me know
I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
Mubasher Sharif
Check out my about.me profile!
http://mubashersharif.blogspot.com
Linked-In Profile
Follow me on Twitter!