Avatar of thomasmutton
thomasmuttonFlag for United Kingdom of Great Britain and Northern Ireland asked on

ASP.NET Gridview images

Hello experts.

I have an SQL statement that says
SELECT TOP 3 *
FROM tbl_UserProfile
ORDER BY UserLoginCount DESC

and it outputs the 3 people with the highest number of logins.

This works and the gridview works fine too but I would like to put an image column in there for 1st, 2nd and 3rd place.

so 1st = gold medal
2nd = silver medal
3rd = bronze medal

How can I do this?
Thanks
<asp:GridView ID="GridView1" runat="server" 
                        DataSourceID="SqlDataSource1" 
                        AutoGenerateColumns="False"  
                        DataKeyNames="UserProfileId"
                        SkinID="TopUsersThisMonth" style="float: left; margin: 0px 0px 10px 0px;">
                        <Columns>
                            <asp:BoundField HeaderText="Pos"  />
                            <asp:BoundField DataField="UserFirstName" HeaderText="User" />
                            <asp:BoundField DataField="UserLoginCount" HeaderText="Logins" />
                        </Columns>
                        <EmptyDataTemplate>There are currently no training modules.</EmptyDataTemplate>
                    </asp:GridView>

Open in new window

Page-1.jpg
ASP.NET

Avatar of undefined
Last Comment
thomasmutton

8/22/2022 - Mon
balochdude

Anurag Agarwal

Add a unbound column in Columns tag in asp:GridView of type image.. i.e <asp:ImageField

then in itemdatabound event set the image URL property for each row.

Anurag
ASKER
thomasmutton

Thats not what i'm looking for. I don't wanto use datatables.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER
thomasmutton

Ok, i will try that anuragal:
SOLUTION
balochdude

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
thomasmutton

hmm, GridView doesnt have an event called Item Data Bound...
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
thomasmutton

O.k, I have done this and it seems good but im not sure what to put for the conditions statements...


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if(e.Row.ItemType == Row.DataRow)
        {
            DataRowView dr = (DataRowView)e.Row.DataItem;
            ImageButton ib = (ImageButton)e.Row.FindControl("ImageButton1");
 
            if (1st place)
            {
                ib.ImageUrl = "gold.jpg"
            }
            if (2nd place)
            {
                ib.ImageUrl = "silver.jpg";
            }
            else if (3rd place)
            {
                ib.ImageUrl = "bronze.jpg";
            }
        }
    }

Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
thomasmutton

i can do this dr["position"].ToString()

but how would i set the positions to 1, 2 and 3?
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Qaiser_Mehmood_Mughal

Sort the records decending and then for the first record set gold and then go further.
ASKER
thomasmutton

in the sql?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
thomasmutton

Thanks Guys