如何在我的面板中设置第一张图像的焦点?

时间:2015-08-11 22:32:26

标签: c# asp.net

您好以下代码集关注我面板中的最后一张图片。 如何将其设置为专注于第一张图像? 我有点理解我必须使用我在飞行中创建的图像按钮ID。但不知道如何。请帮助。

 var fileIdx = 0;     
foreach (Tripclass Trip in TripsByTripIds )
      {
          fileIdx++;
          ImageButton imageButton = new ImageButton(){ ID = "imageBtn" + fileIdx };
          imageButton.ImageUrl = "~/" +Trip.CorridorName+"/"+Trip.Time+"/"+Trip.ImgFileName;
          imageButton.Height = Unit.Pixel(100);
          imageButton.Style.Add("padding", "5px");
          imageButton.Width = Unit.Pixel(100);
          imageButton.Click += new ImageClickEventHandler(imageButton_Click);
          AMSPanel1.Controls.Add(imageButton);
          AMSPanel1.Height = Unit.Pixel(860);
          imageButton.Focus();
      }

1 个答案:

答案 0 :(得分:1)

var fileIdx = 0;     
foreach (Tripclass Trip in TripsByTripIds )
  {
      fileIdx++;
      ImageButton imageButton = new ImageButton(){ ID = "imageBtn" + fileIdx };
      imageButton.ImageUrl = "~/" +Trip.CorridorName+"/"+Trip.Time+"/"+Trip.ImgFileName;
      imageButton.Height = Unit.Pixel(100);
      imageButton.Style.Add("padding", "5px");
      imageButton.Width = Unit.Pixel(100);
      imageButton.Click += new ImageClickEventHandler(imageButton_Click);
      AMSPanel1.Controls.Add(imageButton);
      AMSPanel1.Height = Unit.Pixel(860);
      if(fileIdx == 1) 
      {
          imageButton.Focus();
      }
  }

唯一改变的是:

自:

imageButton.Focus();

要:

if(fileIdx == 1) 
      {
          imageButton.Focus();
      }