2017-12-07 6 views
0

私は60の画像制御を持っています。複数の画像を配列やリストにC#で制御する方法は?

  1. すべての画像は、アレイ
  2. に、私は6桁のロール全くない制御置く:私は2つの要件があります。そして私は次の10枚の画像への最初の10個のイメージコントロールの指標に最初の数字は、2桁目を一致させたいというように... 次は私のコードです:

protected void Page_Load(object sender, EventArgs e) 
{ 
     //for roll no 
     int rollNo = int.Parse(Request.QueryString["RollNo"]); 
     var rollNoArray = rollNo.ToString().Select(t => 
      int.Parse(t.ToString())).ToArray(); 
     int index1=0; 
      int index2=0, index3=0, index4 = 0 
      ,index5 = 0, index6 = 0; 
     for (int i = 0; i < rollNoArray.Length; i++) 
     { 
      //Response.Write(rollNoArray[i]+"<br>"); 
      LBLRollNo.Text += "&nbsp;&nbsp;&nbsp;" + 
      rollNoArray[i].ToString(); 
      if (i == 0) 
      { 
       index1 = rollNoArray[0]; 
      } 
      if (i == 1) 
      { 
       index2 = rollNoArray[1]; 
      } 
      if (i == 2) 
      { 
       index3 = rollNoArray[2]; 
      } 
      if (i == 3) 
      { 
       index4 = rollNoArray[3]; 
      } 
      if (i == 4) 
      { 
       index5 = rollNoArray[4]; 
      } 
      if (i == 5) 
      { 
       index6 = rollNoArray[5]; 
      } 
     } 
     Response.Write(index1); 

     //index 
     matchBubbles(index1); 
     } 
    } 
     public void matchBubbles(int index) 
     { 
     Image[] a =new Image[10]; 
     for (int i = 0; i < 10; i++) 
     { 
      a[0] = Image0; 
      a[1] = Image1; 
      a[2] = Image2; 
      a[3] = Image3; 
      a[4] = Image4; 
      a[5] = Image5; 
      a[6] = Image6; 
      a[7] = Image7; 
      a[8] = Image8; 
      a[9] = Image9; 

      if (index == a[i]) 
      { 

      } 
     } 
} 

は私が操作したいですpsdファイルは、以前の.aspxページから返されたものです。私のフォルダ内の画像は、ロールのインデックスに対して正確な場所に挿入する必要があります。ロール番号の各桁に応じて画像を挿入します。私を助けてください! 私を助けてください。ここ

+0

接頭辞申し訳ありませんが、私はあなたが探しているものを得ることはありませんか?ロールナンバーが123456であると仮定して、あなたの予想される結果は何ですか? – Mike

+0

こんにちはマイク私は実際に私のロールのすべての桁の下に10枚の画像があります。いいえ、私はその画像がロール番号の値と等しいインデックスを見えるようにします。 – waqasqureshi

+0

60個の画像が同じ配列(インデックス0〜59)、または6個の配列にそれぞれ10個の画像がありますか? – Mike

答えて

0

は、他のヒントの多くが付属しての提案です: は、すべて持っている場合は、あなたのDefault.aspxファイル(ないdefault.aspx.cs)にこれを入力して、あなたはWebフォームプロジェクトを持っていると仮定すると、

<asp:Panel ID="HeaderPanel" runat="server"> 
     <h1>Enter image roll sequence here</h1> 
     <asp:TextBox ID="RollNo" runat="server" Text=""></asp:TextBox><asp:Button ID="Button1" runat="server" Text="send" OnClick="Button1_Click" /> 
     <asp:Label ID="LBLRollNo" runat="server" Text="Text coming in from QueryString will end up here after postback"></asp:Label> 
    </asp:Panel>  

    <asp:Panel ID="ImagePanel" runat="server"> 
    </asp:Panel> 

は、その後、あなたのdefault.aspx.csファイルにこれを貼り付けることができます(または任意の名前あなたの代わりに使用します:別のファイルにこの出来事は、よくして、あなたはその特定の一つにそれをすべて挿入し

protected void Page_Load(object sender, EventArgs e) 
     { 
      // This happens whenever there is a rollno variable coming in from the querystring 
      if (Request.QueryString["RollNo"] != null) 
      { 
       string RollNo = Request.QueryString["RollNo"];     
       ShowImages(RollNo); 
      } 
     } 

     // this happens when you enter the roll numbers in the text box and hit the send button 
     protected void Button1_Click(object sender, EventArgs e) 
     { 
      if (!string.IsNullOrEmpty(RollNo.Text)) 
      { 
       LBLRollNo.Text = " Selected roll numbers" + RollNo.Text; 
       ShowImages(RollNo.Text); 
      } 
     } 

     // Roll variable is the roll number. Imageno is the image number inside each Roll. And this information is stored in the image ID attribute. 
     protected void ShowImages(string RollNumbers) 
     { 
      LBLRollNo.Text = " Selected roll numbers" + RollNumbers; 
      var rollNoArray = RollNumbers.Select(t => int.Parse(t.ToString())).ToArray(); 

      foreach (int rollno in rollNoArray) 
      { 
       // add a HTML newline, just to make it more neat 
       Literal templiteral = new Literal(); 
       templiteral.Text = "<br/>"; 
       ImagePanel.Controls.Add(templiteral); 

       Label templabel = new Label(); 
       templabel.Text = "Images in roll number " + rollno.ToString(); 
       ImagePanel.Controls.Add(templabel); 

       // Lay out the images belonging to this roll number (rollno) 
       for (int Imageno = 0; Imageno <= 5; Imageno++) 
       { 
        string identity = "ident|" + rollno.ToString() + "|" + Imageno.ToString() + "|"; // The IDs of each image on-screen will bear an ID like this: ident|0_0| 
        Image tempimage = new Image(); 
        tempimage.ID = identity; 
        ImagePanel.Controls.Add(tempimage); 
       } 
      } 
     } 

     // This routine lays out all rolls and images in one go 
     protected void LayOutImages() 
     { 
      for (int Roll = 0; Roll <= 10; Roll++) 
      { 
       Label templabel = new Label(); 
       templabel.Text = "Roll number " + Roll.ToString(); 
       ImagePanel.Controls.Add(templabel); 

       for (int Imageno = 0; Imageno <= 5; Imageno++) 
       { 
        string identity = "ident|" + Roll.ToString() + "|" + Imageno.ToString() + "|"; // The IDs of each image on-screen will bear an ID like this: ident|0_0| 
        Image tempimage = new Image(); 
        tempimage.ID = identity; 
        ImagePanel.Controls.Add(tempimage); 
       } 
       Literal templiteral = new Literal(); 
       templiteral.Text = "<br/>"; 
       ImagePanel.Controls.Add(templiteral); 
      } 
     } 

実行してください画像コントロールの配列は必要ありません。クエリ文字列に変数を入力するか、テキストボックスにロール番号を設定することができます。ところで。クエリ文字列からwqith 0で始まる文字列配列を解析すると、先頭のゼロは考慮されませんが、この値は固定されています。

enter image description here

アイデアは、各画像はそれが属するとどのような画像数の画像は、任意のロール

ホープ、これはそのように

0

を助けているものロール番号を伝えるのアイデンティティを持っているということです場合は、簡単な方法で行うことができます。

protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!IsPostBack) 
     { 
      //Check Roll No query string cannot be null 
      if (Request["RollNo"] != null) 
      { 
       //Check Roll No cannot exeed 6 digits 
       if (Request["RollNo"].Length <= 6) 
       { 
        string RollNo = Request["RollNo"]; 

        //Check Roll No. must be all digits 
        int iRollNo; 
        if (Int32.TryParse(RollNo, out iRollNo)) 
        { 
         //Prefix with zero for RollNo less than 6 digits 
         if (RollNo.Length < 6) 
         { 
          RollNo = new String('0', 6 - RollNo.Length) + RollNo; 
         } 

         //Display 6 images 
         Image1.ImageUrl = "~/Number/" + RollNo[0] + ".png"; 
         Image2.ImageUrl = "~/Number/" + RollNo[1] + ".png"; 
         Image3.ImageUrl = "~/Number/" + RollNo[2] + ".png"; 
         Image4.ImageUrl = "~/Number/" + RollNo[3] + ".png"; 
         Image5.ImageUrl = "~/Number/" + RollNo[4] + ".png"; 
         Image6.ImageUrl = "~/Number/" + RollNo[5] + ".png"; 
        } 
       } 
      } 
     } 
    } 

Put 10 images in website

結果

RollNo場合。すべての数字または6桁を超える数字ではなく、RollNoの場合は と表示されません。以下6桁、ゼロ

enter image description here

関連する問題