如何动态地一个接一个地显示图像

时间:2016-03-22 05:53:23

标签: c# html css asp.net

我在asp.net工作,我是新手。我被赋予了一个任务,我必须显示任何对象的历史。对象在许多位置传输,其位置从DB跟踪。 通过current_location列。 有3个位置,如1.外面2.内部3. Ocupied。

我需要做的是每当用户点击对象历史记录时。然后它必须用3个图像(outside.png,inside.png,occupied.png)显示它的所有历史记录。

我的意思是先说对象在外面,然后在内部然后占用,然后历史必须通过以下图像显示:

Outside.png ->Inside.png->Occupied.png必须使用html,javascript和c#才能完成。

如何做到这一点?我只需要逻辑来做到这一点?

1 个答案:

答案 0 :(得分:0)

string []images = new string [] { "<img src=\"Outside.png\">", "<img src=\"Inside.png\">", "<img src=\"Occupied.png\">" };
SqlConnection dbconn = new SqlConnection ("user id=username;" + 
        "password=password;server=serverurl;database=database;"
        ); //change username, password, serverurl, and database to what you use to connect to your database
dbconn.Open ();
SqlCommand command = new SqlCommand ("SELECT current_location FROM TABLE_NAME WHERE THING=",dbconn); //change TABLE_NAME to the name of your table, and change "WHERE THING=" to what you use to specify which thing
SqlReader reader = command.ExecuteReader ();
while (reader.Read ())
{
    Response.Write (images [reader.GetInt32(0)]);
}
相关问题