473,473 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Convert values into Images.

I have created a table MSSQL that contain values and published into Datagrid.
The table is typically like this..

Tbl

Article Rating Count
1 3 3
2 0 0
3 2 1
4 4 5

Now I would like to Display images like Star instead of Numbers in the
Rating Column. Typically like this

Article Rating Count
1 * * * 3
2 - 0
3 ** 1
4 **** 5
i am new to ASP.NET, I am trying to figure it out but have no idea. any help ?

THx

Nov 19 '05 #1
4 1417
use the inbuilt DataGrid.OnItemDataBound event

Here you can access item by item your data as its databound and set the text
appropriatly

so, if you datagrd looks like this

<asp:Datagrid id="dg" runat="server" autogeneratecolumns="false">
<Columns>
<asp:BoundColumn DataField="Article" HeaderText="Article"/>
<asp:BoundColumn DataField="Rating" Visible="false"/>
<asp:TemplateColumn HeaderText="Rating">
<ItemTemplate>
<asp:Label id="lblStarRating" runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Count" HeaderText="Count"/>
</Columns>
</asp:DataGrid>

Then set your ItemDataBound event though your Vis Studio GUI and do this in
the method

private void dg_OnItemDataBound(object Sender, DataGridItemEventArgs e)
{
if(e.Item.ItemType != ListItemType.Header && e.Item.ItemType !=
ListItemType.Footer)
{
Label MyLabel = (Labe)e.Item.FindControls("lblStarRating");
MyLabel = "";
int i = Convert.ToInt32(e.ItemCells[1].Text);
for(int j = 0; j < i; j++)
MyLabe += "*";
}
}

HTH

"velu" <ve**@discussions.microsoft.com> wrote in message
news:C1**********************************@microsof t.com...
I have created a table MSSQL that contain values and published into
Datagrid.
The table is typically like this..

Tbl

Article Rating Count
1 3 3
2 0 0
3 2 1
4 4 5

Now I would like to Display images like Star instead of Numbers in the
Rating Column. Typically like this

Article Rating Count
1 * * * 3
2 - 0
3 ** 1
4 **** 5
i am new to ASP.NET, I am trying to figure it out but have no idea. any
help ?

THx

Nov 19 '05 #2
Appreciated your fast reply. But i am not able to understand it.

I could not able to find the On "OnItemDataBound". On itemDatabound…

is there any equaling VB.NEt Code.

i have developed with VB.NET i am not ware of c#...(sorry)

thx

"Grant Merwitz" wrote:
use the inbuilt DataGrid.OnItemDataBound event

Here you can access item by item your data as its databound and set the text
appropriatly

so, if you datagrd looks like this

<asp:Datagrid id="dg" runat="server" autogeneratecolumns="false">
<Columns>
<asp:BoundColumn DataField="Article" HeaderText="Article"/>
<asp:BoundColumn DataField="Rating" Visible="false"/>
<asp:TemplateColumn HeaderText="Rating">
<ItemTemplate>
<asp:Label id="lblStarRating" runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Count" HeaderText="Count"/>
</Columns>
</asp:DataGrid>

Then set your ItemDataBound event though your Vis Studio GUI and do this in
the method

private void dg_OnItemDataBound(object Sender, DataGridItemEventArgs e)
{
if(e.Item.ItemType != ListItemType.Header && e.Item.ItemType !=
ListItemType.Footer)
{
Label MyLabel = (Labe)e.Item.FindControls("lblStarRating");
MyLabel = "";
int i = Convert.ToInt32(e.ItemCells[1].Text);
for(int j = 0; j < i; j++)
MyLabe += "*";
}
}

HTH

"velu" <ve**@discussions.microsoft.com> wrote in message
news:C1**********************************@microsof t.com...
I have created a table MSSQL that contain values and published into
Datagrid.
The table is typically like this..

Tbl

Article Rating Count
1 3 3
2 0 0
3 2 1
4 4 5

Now I would like to Display images like Star instead of Numbers in the
Rating Column. Typically like this

Article Rating Count
1 * * * 3
2 - 0
3 ** 1
4 **** 5
i am new to ASP.NET, I am trying to figure it out but have no idea. any
help ?

THx


Nov 19 '05 #3
To get to the ItemDataBound command, click on your datagrid in design view,
click on properties,
then click on events (yellow lightening at top of the properties window)

If you have the DataGrid selected, you'll see the ItemDataBound property,
double click in the space next to it and it will create a method in your
code behind.
something like:
private void [DataGridID]_OnItemDataBound

if you are not using visual studio, you can just use this as follows:
<asp:Datagrid id="dg" runat="server" OnItemDataBound="dg_ItemDataBound"

But you will then have to declare the method as public
public void dg_ItemDataBound

i'm not much of a VB programmer, so i'll try write the code (aspx remains
the same)

public sub dg_ItemDataBound(sender as Object, e as DataGridItemEventArgs)
BEGIN
IF e.Item.ItemType <> ListItemType.Header AND e.Item.ItemType <>
ListItemType.ItemFooter THE
DIM MyLabel as Label
Label = cType(e.Item.FindControl("lblStarRating"), Label)
DIM i as int
i = Convert.ToInt32(e.Item.Cells(1).Text)
DIM j as int = 0
Label.Text = ""
FOR j = 1 to i
Label.Text += "*"
NEXT
END IF
END

Some of the code may have been a bit wrong, but hopefully it'll set you on
the right track
Good Luck

"velu" <ve**@discussions.microsoft.com> wrote in message
news:69**********************************@microsof t.com...
Appreciated your fast reply. But i am not able to understand it.

I could not able to find the On "OnItemDataBound". On itemDatabound.

is there any equaling VB.NEt Code.

i have developed with VB.NET i am not ware of c#...(sorry)

thx

"Grant Merwitz" wrote:
use the inbuilt DataGrid.OnItemDataBound event

Here you can access item by item your data as its databound and set the
text
appropriatly

so, if you datagrd looks like this

<asp:Datagrid id="dg" runat="server" autogeneratecolumns="false">
<Columns>
<asp:BoundColumn DataField="Article" HeaderText="Article"/>
<asp:BoundColumn DataField="Rating" Visible="false"/>
<asp:TemplateColumn HeaderText="Rating">
<ItemTemplate>
<asp:Label id="lblStarRating" runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Count" HeaderText="Count"/>
</Columns>
</asp:DataGrid>

Then set your ItemDataBound event though your Vis Studio GUI and do this
in
the method

private void dg_OnItemDataBound(object Sender, DataGridItemEventArgs e)
{
if(e.Item.ItemType != ListItemType.Header && e.Item.ItemType !=
ListItemType.Footer)
{
Label MyLabel = (Labe)e.Item.FindControls("lblStarRating");
MyLabel = "";
int i = Convert.ToInt32(e.ItemCells[1].Text);
for(int j = 0; j < i; j++)
MyLabe += "*";
}
}

HTH

"velu" <ve**@discussions.microsoft.com> wrote in message
news:C1**********************************@microsof t.com...
>I have created a table MSSQL that contain values and published into
>Datagrid.
> The table is typically like this..
>
> Tbl
>
> Article Rating Count
> 1 3 3
> 2 0 0
> 3 2 1
> 4 4 5
>
> Now I would like to Display images like Star instead of Numbers in the
> Rating Column. Typically like this
>
> Article Rating Count
> 1 * * * 3
> 2 - 0
> 3 ** 1
> 4 **** 5
> i am new to ASP.NET, I am trying to figure it out but have no idea. any
> help ?
>
> THx
>


Nov 19 '05 #4
Thx Grant Merwitz, it worked. here is the VB.Net version.. but need more
help..!

If ((e.Item.ItemType <> ListItemType.Header) And (e.Item.ItemType <>
ListItemType.Footer)) Then
Dim MyLabel As Label
MyLabel = CType(e.Item.FindControl("lblStarRating"), label)
Dim i As Int32
i = Convert.ToInt32(e.Item.Cells(3).Text)
Dim j As Int32 = 0

Mylabel.Text = ""
For j = 1 To i
Mylabel.text += “*”
Next

'End If

Instead of characters, I would like to display images. I did try this, with
select case in VB.neT but I could not able to do it..

If ((e.Item.ItemType <> ListItemType.Header) And (e.Item.ItemType <>
ListItemType.Footer)) Then
'Dim MyLabel As Image
'Dim label1 As Label

'MyLabel = CType(e.Item.FindControl("lblStarRating"), Image)
Dim i As Int32
i = Convert.ToInt32(e.Item.Cells(3).Text)

Dim ImageButton1, ImageButton2, ImageButton3, ImageButton4,
ImageButton5 As ImageButton

'ImageButton1.ImageUrl =
Server.MapPath("/Sample/Rating_jk/amdLogo.jpg")

Select Case i
Case "1"

ImageButton1.EnableViewState = True
ImageButton2.EnableViewState = False
ImageButton3.EnableViewState = False
ImageButton4.EnableViewState = False
ImageButton5.EnableViewState = False

Case Else
ImageButton1.EnableViewState = False
ImageButton2.EnableViewState = False
ImageButton3.EnableViewState = False
ImageButton4.EnableViewState = False
ImageButton5.EnableViewState = False
End Select

Apart from displaying images, I also would like to remove this rating column
in number from the table. Any ideas how to disable a particular column?

Nov 19 '05 #5

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

Similar topics

2
by: James dean | last post by:
Do i have to create an index pallette. How do i do that?. Or, Can i not just make an ordinary 8pp pixel format without this indexed problem...... *** Sent via Developersdex...
7
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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 projectplanning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.