Ich habe 12 zufällige Bilder von 2 Dateien. Ich möchte die Rahmenfarbe eines Bildes immer dann ändern, wenn darauf geklickt wird. Ich möchte auch speichern, welches Bild in einer Datenbank angeklickt wird. hier ist der Code, den ich für meine zufälligen Bilder aus 2 Ordnern bin mit: „Erwachsene“ und „Kinder“Wie zu wissen, welches zufällige Bild in asp.net geklickt wird
int i = 1, j=1;
protected void Page_Load(object sender, EventArgs e)
{
string Image2Display1 = GetRandomImageAdult();
RandomImg1.ImageUrl = Path.Combine("~/adults", Image2Display1);
i++;
if (RandomImg1.BorderColor.Equals()
RandomImg1_click();
string Image2Display2 = GetRandomImageChildren();
RandomImg2.ImageUrl = Path.Combine("~/Children", Image2Display2);
j++;
string Image2Display3 = GetRandomImageChildren();
RandomImg3.ImageUrl = Path.Combine("~/Children", Image2Display3);
j++;
string Image2Display4 = GetRandomImageAdult();
RandomImg4.ImageUrl = Path.Combine("~/adults", Image2Display4);
i++;
string Image2Display5 = GetRandomImageChildren();
RandomImg5.ImageUrl = Path.Combine("~/Children", Image2Display5);
j++;
string Image2Display6 = GetRandomImageAdult();
RandomImg6.ImageUrl = Path.Combine("~/adults", Image2Display6);
i++;
string Image2Display7 = GetRandomImageChildren();
RandomImg7.ImageUrl = Path.Combine("~/Children", Image2Display7);
j++;
string Image2Display8 = GetRandomImageAdult();
RandomImg8.ImageUrl = Path.Combine("~/adults", Image2Display8);
i++;
string Image2Display9 = GetRandomImageAdult();
RandomImg9.ImageUrl = Path.Combine("~/adults", Image2Display9);
i++;
string Image2Display10 = GetRandomImageChildren();
RandomImg10.ImageUrl = Path.Combine("~/Children", Image2Display10);
j++;
string Image2Display11 = GetRandomImageAdult();
RandomImg11.ImageUrl = Path.Combine("~/adults", Image2Display11);
i++;
string Image2Display12 = GetRandomImageChildren();
RandomImg12.ImageUrl = Path.Combine("~/Children", Image2Display12);
j++;
}
public string GetRandomImageAdult()
{
Random rnd = new Random();
for (int ii = 1; ii <= i; ii++)
rnd.Next();
string[] images = Directory.GetFiles(MapPath("~/adults"));
string Image2Display = images[rnd.Next(images.Length)];
return Path.GetFileName(Image2Display);
}
public string GetRandomImageChildren()
{
Random rnd = new Random();
for (int jj = 1; jj <= j; jj++)
rnd.Next();
string[] images = Directory.GetFiles(MapPath("~/Children"));
string Image2Display = images[rnd.Next(images.Length)];
return Path.GetFileName(Image2Display);
}
und hier ist die Quelle:
<div>
<asp:Image ID="RandomImg1" runat="server" Width="200px" />
<asp:Image ID="RandomImg2" runat="server" Width="200px" />
<asp:Image ID="RandomImg3" runat="server" Width="200px" />
<asp:Image ID="RandomImg4" runat="server" Width="200px" />
<asp:Image ID="RandomImg5" runat="server" Width="200px" />
<asp:Image ID="RandomImg6" runat="server" Width="200px" />
<asp:Image ID="RandomImg7" runat="server" Width="200px" />
<asp:Image ID="RandomImg8" runat="server" Width="200px" />
<asp:Image ID="RandomImg9" runat="server" Width="200px" />
<asp:Image ID="RandomImg10" runat="server" Width="200px" />
<asp:Image ID="RandomImg11" runat="server" Width="200px" />
<asp:Image ID="RandomImg12" runat="server" Width="200px" />
</div>
mir bitte mit wahrscheinlich „ImageButton_Click helfen ". Ich weiß nicht, wie ich das machen soll. danke.
mit Post zurück, warum Sie Tag 'haben hier jquery'? Ich habe gesehen, dass du jQuery nicht in deinem Code benutzt hast. – Thatkookooguy