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
>