wrap your aspx code in a repeater and use databinder to get value from column name
<a class="full" href="<%# DataBinder.Eval(Container.DataItem, "NavigationUrl").ToString().Split(',')[0] %>">
</a>
NavigationUrl is the column name that contains the url/text
so like this:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<li>
<a class="full" href="<%# DataBinder.Eval(Container.DataItem, "NavigationUrl").ToString().Split(',')[0] %>">
</a>
</li>
</ItemTemplate>
</asp:Repeater>
for you it will look like this:
<ItemTemplate>
<table>
<tr>
<td>
<a class="full" href="<%# DataBinder.Eval(Container.DataItem, "oplLink").ToString().Split(',')[0] %>">
</a>
</td>
</tr>
</table>
</ItemTemplate>
in you aspx.cs codebehind add the databinding to the list:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.IsPostBack)
BindData();
}
private void BindData()
{
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["QMS Links"];
DataTable Dt = list.Items.GetDataTable();
Repeater1.DataSource = Dt;
Repeater1.DataBind();
}
that should do the trick!
if codebehind only do this within createchildcontrols
:
Repeater Repeater1 = new Repeater1();
web = SPContext.Current.Web;
list = web.Lists[_ListName];
Dt = list.Items.GetDataTable();
Repeater1 = new Repeater();
Repeater1.ItemDataBound += new RepeaterItemEventHandler(Repeater1_ItemDataBound);
Repeater1.DataSource = Dt;
Repeater1.DataBind();
Controls.Add(Repeater1);
now make the event for repeater:
private void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
try
{
string urlImageClick = DataBinder.Eval(e.Item.DataItem, "NavigationUrl").ToString().Split(',')[0];
Repeater1.Controls.Add(new LiteralControl("<a target='_parent' href='" + urlImageClick + "'>"));
}
catch (Exception a)
{
reportError.WriteError("Control ID: " + a.Source, a.Message, " Repeater1_ItemDataBound: at " + a.StackTrace, SPContext.Current.Site.Url);
}
}
above will give you a list of urls (href links)
so to clarify:
DataBinder.Eval(e.Item.DataItem, "NavigationUrl").ToString().Split(',')[0];
the above gives you the url part
DataBinder.Eval(e.Item.DataItem, "NavigationUrl").ToString().Split(',')[1];
above gives you the text, you need to change the NavigationUrl part to what ever the column is called that holds that value!
the repeater repeats for each item within the list that is passed into the datatable and iterated over and over again untill all items are done! (less code)
now for image its the same thing just change the html:
<a class="full" href="<%# DataBinder.Eval(Container.DataItem, "NavigationUrl").ToString().Split(',')[0]>">
<img src="<%# DataBinder.Eval(Container.DataItem, "ImageUrl").ToString().Split(',')[0] %>" class="full" alt="Tile" width="150px" height="160px"/>
</a>
the above code will display an image, if you click on the image it will direct you to where ever the link is set ;) , so within your list you could have a hyperlink and an image within the same row as two columns, set the link first and set the image within the link. Same consept for anything else!
same goes for codebehind ;) , to have a hyperlink text, do as above, this time instead of adding an image within the "a" tag you can add a lable or just bind directly as iv shown you above within the databind part!