I
Iain
Hi All
Hope someone can assist.
Using Borland Developer Studio 2006, C# .Net Application.
I have a datagrid the source of whioch is a database table.
I can populate the datagrid with no problems.
The first column in the datagrid contains the url for an image which I
want to display in column 6 of the same row.
The image is stored in a sub-directory.
Can anyone please advise me how I would accomplish this.
I have included the relevant snippets of code below.
Thanks in advance for any assistance offered
Iain
------------------------------------------------------------------------------------------------------------------------------------------------------------
<asp:datagrid id="PageImages" runat="server" width="82%"
borderwidth="1px" borderstyle="Solid"
bordercolor="#C0FFFF"
enableviewstate="true" allowsorting="True">
<Columns>
<ASP:BoundColumn datafield="ImageName" headertext="Image Name"></
ASP:BoundColumn>
<ASP:BoundColumn datafield="ImageText" headertext="Image text"></
ASP:BoundColumn>
<ASP:BoundColumn datafield="AlternateText" headertext="Alternate
text"></ASP:BoundColumn>
<ASP:BoundColumn datafield="HRef" headertext="Internet Address
(URL)"></ASP:BoundColumn>
<ASP:BoundColumn datafield="Sequence" headertext="Display
Sequence"></ASP:BoundColumn>
<ASP:BoundColumn datafield="Published" headertext="Published"></
ASP:BoundColumn>
<asp:TemplateColumn HeaderText="Displayed Image">
<ItemTemplate>
<asp:Image Runat="server" ID="Image1" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
---------------------------------------------------------------
Code Behind
---------------------------------------------------------------
public void PageImages_OnItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType != ListItemType.Header && e.Item.ItemType !=
ListItemType.Footer)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
// get the image name from the first column : No Problem Here
string LImageName = e.Item.Cells[0].Text;
// *************************************************************
// At this point I want to add an image to the cell
// using the image name taken from the first column
e.Item.Cells[6]................................. = LImageName;
// *************************************************************
}
}
}
Hope someone can assist.
Using Borland Developer Studio 2006, C# .Net Application.
I have a datagrid the source of whioch is a database table.
I can populate the datagrid with no problems.
The first column in the datagrid contains the url for an image which I
want to display in column 6 of the same row.
The image is stored in a sub-directory.
Can anyone please advise me how I would accomplish this.
I have included the relevant snippets of code below.
Thanks in advance for any assistance offered
Iain
------------------------------------------------------------------------------------------------------------------------------------------------------------
<asp:datagrid id="PageImages" runat="server" width="82%"
borderwidth="1px" borderstyle="Solid"
bordercolor="#C0FFFF"
enableviewstate="true" allowsorting="True">
<Columns>
<ASP:BoundColumn datafield="ImageName" headertext="Image Name"></
ASP:BoundColumn>
<ASP:BoundColumn datafield="ImageText" headertext="Image text"></
ASP:BoundColumn>
<ASP:BoundColumn datafield="AlternateText" headertext="Alternate
text"></ASP:BoundColumn>
<ASP:BoundColumn datafield="HRef" headertext="Internet Address
(URL)"></ASP:BoundColumn>
<ASP:BoundColumn datafield="Sequence" headertext="Display
Sequence"></ASP:BoundColumn>
<ASP:BoundColumn datafield="Published" headertext="Published"></
ASP:BoundColumn>
<asp:TemplateColumn HeaderText="Displayed Image">
<ItemTemplate>
<asp:Image Runat="server" ID="Image1" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
---------------------------------------------------------------
Code Behind
---------------------------------------------------------------
public void PageImages_OnItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType != ListItemType.Header && e.Item.ItemType !=
ListItemType.Footer)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
// get the image name from the first column : No Problem Here
string LImageName = e.Item.Cells[0].Text;
// *************************************************************
// At this point I want to add an image to the cell
// using the image name taken from the first column
e.Item.Cells[6]................................. = LImageName;
// *************************************************************
}
}
}