-2
variable = reader.GetInt32(reader.GetOrdinal("seatno"));
if (variable == 1)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton4");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 2)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton6");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 3)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton7");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 4)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton8");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 5)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton9");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 6)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton10");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 7)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton11");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 8)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton12");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 9)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton13");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 10)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton14");
// ImageButton img2 = (ImageButton)img1.FindControl("ImageButton4");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 11)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton15");
// ImageButton img2 = (ImageButton)img1.FindControl("ImageButton4");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 12)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton20");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 13)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton21");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 14)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton22");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 15)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton23");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 16)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton24");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 17)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton25");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 18)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton26");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 19)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton27");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 20)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton15");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
if (variable == 21)
{
ImageButton img1 = (ImageButton)GridView2.Rows[0].Cells[0].FindControl("ImageButton26");
// ImageButton img2 = (ImageButton)img1.FindControl("ImageButton4");
img1.ImageUrl = "~/images/saveseat.jpg";
img1.Enabled = false;
}
請告訴我怎樣可以使這個代碼更優秀,short.here我必須去通過每個如果condition.which是時候consuming.i需要使它這樣,如果變量值是4,那麼它必須直接轉到4而不是通過每個if。需要知道如何使代碼更
if (image4click)
{
a = 1;
}
if (image4click1)
{
a = 2;
}
if (image4click2)
{
a = 3;
}
if (image4click3)
{
a = 4;
}
if (image4click4)
{
a = 5;
}
if (image4click5)
{
a = 6;
}
in this image4click is boolean variable.how to shorten this make it better.
非常感謝.. :) :) – nimmy
不客氣:) –