473,414 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Changing Datalist items at run time

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)co ntainer).DataItem,
"ThumbImagePath"));

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

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

hpl1.ImageUrl = "Photos/"+strVals;

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

}

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

Thanks in advance
Sanju
Sep 13 '06 #1
1 2375
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.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"sanju" <sa***@elogic.co.nzwrote in message
news:OX**************@TK2MSFTNGP06.phx.gbl...
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)co ntainer).DataItem,
"ThumbImagePath"));

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

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

hpl1.ImageUrl = "Photos/"+strVals;

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

}

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

Thanks in advance
Sanju

Sep 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Kaung Htut O via DotNetMonster.com | last post by:
Hi to all Is there a way to access Datalist Footer's Control properties from outside of datalist event. Pls note that I mean not a datagrid, only for datalist. Thanks Kaung Htut Oo
1
by: Mike Malter | last post by:
I take it that the only way to add rows to a DataList control is through DataBind? If not, how do I manually add rows to a DataList control? I have searched everywhere and can't find an example...
4
by: jenn | last post by:
Hi Anyone knows how to access to a value of a row in a datalist. Something like this in datagrid Dim str = MyDataGrid.Cell(0).tex I would like something like this Dim str =...
10
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
5
by: Patrick.O.Ige | last post by:
I'm binding a CheckBoxlist below in the ItemDataBound(the CheckBoxList is in a Datalist) By doing "li.Selected = True" i can see all the checkBoxes are selected. But what i want is to be able...
4
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
2
by: Fabiano | last post by:
Please, i need to hide a Item(Collumn) of a DataList that is inside of another DataList based on some data that i my database returns. For a sample i created the code above, but it doesn't work....
6
by: Paul | last post by:
I am trying to use a DataList and the ItemTemplate. I am binding the Datalist to a SQL query that gives me a list of Items with a Parent Category. I want to loop through all the items, but...
1
by: David | last post by:
Hi, This one appears a little strange to me. Here is the scenario. I load a datalist the first time a page is run. The page has a !IsPostback and the datalist gets loaded at this point. I...
1
by: studen771 | last post by:
Thanks in advance to anyone who can help :) I have my datalist bound to a normal, single dimension string array (with three elements) as its data source. In the scripting for the datagrid, I have...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.