Changing Datalist items at run time

S

sanju

Hi ,

I am displaying 5 photos of a user(getting image path from database) and
binding them to hyperlink control and adding that Hyperlink control to
Datalist container in code behind file.

Now I want to change last 2 photos of user with another image while loading
the page.

My situation is "I want to hide/mask photos of user depending on the
permission level of who accessing the website.if one is paid member i want
to display all or for free members i need to display few.

................ code ......

try

{

DataList1.ItemTemplate = new DatalistHyperLinkColumn();

DataList1.DataSource =ds1;


DataList1.DataBind();

}

catch (Exception ex)

{

Response.Write(ex.ToString());

}

finally

{

PhotosConnection.Close();


}

}

public class DatalistHyperLinkColumn : ITemplate

{

public DatalistHyperLinkColumn()

{

//Add constructor stuff here

}

public void InstantiateIn(Control container)

{



HyperLink hpl = new HyperLink();

hpl.DataBinding += new EventHandler(this.BindLabelColumn);

container.Controls.Add(hpl);

}

public void BindLabelColumn(object sender, EventArgs e)

{

HyperLink hpl1 = (HyperLink)sender;


DataListItem container = (DataListItem)hpl1.NamingContainer;

String strVals =
Convert.ToString(DataBinder.Eval(((DataListItem)container).DataItem,
"ThumbImagePath"));

String lImagePath =
Convert.ToString(DataBinder.Eval(((DataListItem)container).DataItem,
"LargeImagePath"));

int pCount1 =
Convert.ToInt32(DataBinder.Eval(((DataListItem)container).DataItem,
"photocount1"));

hpl1.ImageUrl = "Photos/"+strVals;

hpl1.NavigateUrl = "Photos/web/" + lImagePath;





}

......................................
plz can one help me put..

Thanks in advance
Sanju
 
E

Eliyahu Goldin

You need to handle ItemDataBound event. In the event handler you can check
the permission level and hide/mask the photos in the item accordingly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top