2016-04-10 9 views
1

私は現在、商品名、商品重量、商品の色、商品の品質、起源、数量を表示しています。行ごとに各項目... 私は各行に2つの項目を、3行には6つの項目を表示したいと思います。最初の項目は、最初の行の右に2番目の項目を左揃えにする必要があります。これは私のコードです。 ダイナミックasp.net

using System; 
 
using System.Collections.Generic; 
 
using System.Data.SqlClient; 
 
using System.Linq; 
 
using System.Web; 
 
using System.Web.UI; 
 
using System.Web.UI.WebControls; 
 

 
public partial class jewellery : System.Web.UI.Page 
 
{ 
 
    public void select_data() 
 
    { 
 
     //String con_str = @"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\asim\bootstrap1 (1)\App_Data\Database.mdf;Integrated Security=True;User Instance=True"; 
 
     String con_str = @"Data Source=KHAN-PC\SQLEXPRESS;Initial Catalog=D:\ASIM\BOOTSTRAP1 (1)\APP_DATA\DATABASE.MDF;Integrated Security=True"; 
 
     //string con_str = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\project\App_Data\Database.mdf;Integrated Security=True"; 
 
     SqlConnection con = new SqlConnection(con_str); 
 
     con.Open(); 
 
     string query = "select * from jewellery1"; 
 
     SqlCommand cmd = new SqlCommand(query, con); 
 
     SqlDataReader reader = cmd.ExecuteReader(); 
 
     int n = 1; 
 
     String id = "Image"; 
 
     while (reader.Read()) 
 
     { 
 
      System.Web.UI.HtmlControls.HtmlGenericControl section = new System.Web.UI.HtmlControls.HtmlGenericControl("section"); 
 
      section.ID = "portfolio"; 
 
      section.Attributes["class"] = "bg-light-gray"; 
 
      System.Web.UI.HtmlControls.HtmlGenericControl row = new System.Web.UI.HtmlControls.HtmlGenericControl("div"); 
 
      row.Attributes["class"] = "row"; 
 
      Byte[] bytes = (Byte[])reader["item_image"]; 
 
      String item_name = (String)reader["item_name"]; 
 
      String color = (String)reader["item_color"];  
 
      String weight = (String)reader["item_weight"]; 
 
      String quality = (String)reader["item_quality"]; 
 
      String clarity = (String)reader["item_clarity"]; 
 
      String origin = (String)reader["item_origin"]; 
 

 

 
      System.Web.UI.HtmlControls.HtmlGenericControl createDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("div"); 
 
      createDiv.ID = "createDiv" + n + 11; 
 
      System.Web.UI.HtmlControls.HtmlGenericControl createDiv1 = 
 
     new System.Web.UI.HtmlControls.HtmlGenericControl("div"); 
 
      System.Web.UI.HtmlControls.HtmlGenericControl hover = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV"); 
 
      hover.Attributes["class"] = "portfolio-hover"; 
 
      System.Web.UI.HtmlControls.HtmlGenericControl hover_content = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV"); 
 
      hover_content.Attributes["class"] = "portfolio-hover-content"; 
 
      System.Web.UI.HtmlControls.HtmlGenericControl i = new System.Web.UI.HtmlControls.HtmlGenericControl("i"); 
 
      i.Attributes["class"] = "fa fa-2x"; 
 
      createDiv1.ID = "createDiv" + n + 12; 
 
      createDiv1.Attributes["class"] = "col-md-4 col-sm-6 portfolio-item zoomIn animated"; 
 
      createDiv1.Attributes["data-wow-duration"] = "1500ms"; 
 
      createDiv1.Attributes["data-wow-delay"] = "100ms"; 
 
      createDiv.Attributes["class"] = "portfolio-caption"; 
 
      LinkButton a = new LinkButton(); 
 
      a.Attributes["class"] = "portfolio-link"; 
 
      a.Attributes["data-toggle"] = "modal"; 
 
      a.Click += new EventHandler(test); 
 
      a.CommandArgument = item_name; 
 
      /* System.Web.UI.HtmlControls.HtmlGenericControl a = new System.Web.UI.HtmlControls.HtmlGenericControl("a"); 
 
      a.Attributes["class"] = "portfolio-link"; 
 
      a.Attributes["data-toggle"] = "modal";*/ 
 
      System.Web.UI.HtmlControls.HtmlGenericControl h1 = new System.Web.UI.HtmlControls.HtmlGenericControl("h4"); 
 
      System.Web.UI.HtmlControls.HtmlGenericControl h2 = new System.Web.UI.HtmlControls.HtmlGenericControl("h4"); 
 
      System.Web.UI.HtmlControls.HtmlGenericControl h3 = new System.Web.UI.HtmlControls.HtmlGenericControl("h4"); 
 
      System.Web.UI.HtmlControls.HtmlGenericControl h4 = new System.Web.UI.HtmlControls.HtmlGenericControl("h4"); 
 
      System.Web.UI.HtmlControls.HtmlGenericControl h5 = new System.Web.UI.HtmlControls.HtmlGenericControl("h4"); 
 
      System.Web.UI.HtmlControls.HtmlGenericControl h6 = new System.Web.UI.HtmlControls.HtmlGenericControl("h4"); 
 

 

 

 
      
 
       h1.Attributes["align"] = "LEFT"; 
 
       h1.Attributes["style"] = "color:black"; 
 
       h1.InnerHtml = "Name &nbsp &nbsp :&nbsp &nbsp " + item_name; 
 
       h2.Attributes["align"] = "RIGHT"; 
 
       h2.Attributes["style"] = "color:black"; 
 
       h2.InnerHtml = "color &nbsp &nbsp &nbsp &nbsp :&nbsp &nbsp " + color; 
 
      
 
      h3.Attributes["align"] = "LEFT"; 
 
      h3.Attributes["style"] = "color:black"; 
 
      h3.InnerHtml = "Weight &nbsp &nbsp: &nbsp &nbsp " + weight; 
 
      h4.Attributes["align"] = "LEFT"; 
 
      h4.Attributes["style"] = "color:black"; 
 
      h4.InnerHtml = "Quality &nbsp&nbsp: &nbsp " + quality; 
 
      h5.Attributes["align"] = "LEFT"; 
 
      h5.Attributes["style"] = "color:black"; 
 
      h5.InnerHtml = "Clarity &nbsp&nbsp: &nbsp " + clarity; 
 
      h6.Attributes["align"] = "LEFT"; 
 
      h6.Attributes["style"] = "color:black"; 
 
      h6.InnerHtml = "Origin &nbsp&nbsp: &nbsp " + origin; 
 

 
      System.Web.UI.HtmlControls.HtmlGenericControl hyp = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV"); 
 
      hyp.Attributes["class"] = "portfolio-link"; 
 

 
      System.Web.UI.WebControls.Image tb = new System.Web.UI.WebControls.Image() { ID = "Image" + n + 10 }; 
 
      tb.Height = 250; 
 
      tb.Width = 500; 
 
      tb.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(bytes); 
 
      hover_content.Controls.Add(i); 
 
      a.Controls.Add(hover); 
 
      a.Controls.Add(hover_content); 
 
      a.Controls.Add(tb); 
 
      createDiv.Controls.Add(h1); 
 
      createDiv.Controls.Add(h2); 
 
      createDiv.Controls.Add(h3); 
 
      createDiv.Controls.Add(h4); 
 
      createDiv.Controls.Add(h5); 
 
      createDiv.Controls.Add(h6); 
 
      createDiv1.Controls.Add(a); 
 
      createDiv1.Controls.Add(createDiv); 
 
      // row.Controls.Add(createDiv1); 
 
      //section.Controls.Add(row); 
 

 
      divid1.Controls.Add(createDiv1); 
 
      Console.WriteLine("{0}\t{1}", reader.GetInt32(0), 
 
       reader.GetString(1)); 
 
      n++; 
 
     } 
 
    } 
 
    protected void test(object sender, EventArgs e) 
 
    { 
 
     String wagerId = ((LinkButton)sender).CommandArgument; 
 
     Response.Redirect("awesome.aspx?eid=" + wagerId); 
 

 
    } 
 
    protected void Page_Load(object sender, EventArgs e) 
 
    { 
 
     if (!IsPostBack) 
 
     { 
 
      select_data(); 
 
     } 
 

 
    } 
 

 

 
    protected void Button1_Click(object sender, EventArgs e) 
 
    { 
 

 
    } 
 
}

更新されたコード ブロあなたのコードは動作しませんでした。私はこのやり方でやってみた。左にH1、右にH2が表示されますが、次の行に表示されるように、h3が中央に表示されます。これを解決できます。

h1.Attributes["class"] = "links left"; 
 
       h1.Attributes["style"] = "color:black"; 
 
       h1.InnerHtml = "Name &nbsp &nbsp :&nbsp &nbsp " + item_name; 
 
       h2.Attributes["class"] = "links right"; 
 
       h2.Attributes["style"] = "color:black"; 
 
       h2.InnerHtml = "color &nbsp &nbsp &nbsp &nbsp :&nbsp &nbsp " + color; 
 
       
 

 
      h3.Attributes["class"] = "links right"; 
 
      h3.Attributes["style"] = "color:black"; 
 
      h3.InnerHtml = "Weight &nbsp &nbsp: &nbsp &nbsp " + weight; 
 
      h4.Attributes["align"] = "LEFT"; 
 
      h4.Attributes["style"] = "color:black"; 
 
      h4.InnerHtml = "Quality &nbsp&nbsp: &nbsp " + quality; 
 

 
    <style> 
 
.mainlinks 
 
    { 
 
    text-align:right; 
 
    margin-top:3px; 
 
    margin-right:10px; 
 
    margin-bottom:0px; 
 
    padding:0px; 
 
    } 
 

 
a.links:link { 
 
    color: #FF0000; text-decoration: none; 
 
    text-align:left; 
 
    margin-left:8px; 
 
    margin-top:300px; 
 
    margin-bottom:0px; 
 
    padding:2px; 
 
    font-family:Arial, Helvetica, sans-serif; 
 
    font-size: 14px; 
 
    } 
 
    
 
.right { float: right } 
 
.left { float: left } 
 

 
</style>

+0

私はこれh2.Attributesを行うと[ "揃える"] = "右"、h2.Attributes [ "揃えます"] =" LEFT "が消えます。 –

答えて

0

次のコードを使用します。 アトリビュート["align"] = "LEFT"部分を削除しました。float:left; width:50%;。必要に応じて幅の割合を調整します。

h1.Attributes["style"] = "color:black;float: left;width: 50%; "; 
h1.InnerHtml = "Name &nbsp &nbsp :&nbsp &nbsp " + item_name; 

h2.Attributes["style"] = "color:black;float: left;width: 50%; "; 
h2.InnerHtml = "color &nbsp &nbsp &nbsp &nbsp :&nbsp &nbsp " + color; 

h3.Attributes["style"] = "color:black;float: left;width: 50%; "; 
h3.InnerHtml = "Weight &nbsp &nbsp: &nbsp &nbsp " + weight; 

h4.Attributes["style"] = "color:black;float: left;width: 50%; "; 
h4.InnerHtml = "Quality &nbsp&nbsp: &nbsp " + quality; 

h5.Attributes["style"] = "color:black;float: left;width: 50%; "; 
h5.InnerHtml = "Clarity &nbsp&nbsp: &nbsp " + clarity; 

h6.Attributes["style"] = "color:black;float: left;width: 50%; "; 
h6.InnerHtml = "Origin &nbsp&nbsp: &nbsp " + origin; 

(私のVSに調整するための変数をコメントアウト)UPDATE

var n = 1; 
      while(n < 5) { 
       System.Web.UI.HtmlControls.HtmlGenericControl createDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("div"); 
       createDiv.ID = "createDiv" + n + 11; 
       System.Web.UI.HtmlControls.HtmlGenericControl createDiv1 = 
      new System.Web.UI.HtmlControls.HtmlGenericControl("div"); 
       System.Web.UI.HtmlControls.HtmlGenericControl hover = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV"); 
       hover.Attributes["class"] = "portfolio-hover"; 
       System.Web.UI.HtmlControls.HtmlGenericControl hover_content = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV"); 
       hover_content.Attributes["class"] = "portfolio-hover-content"; 
       System.Web.UI.HtmlControls.HtmlGenericControl i = new System.Web.UI.HtmlControls.HtmlGenericControl("i"); 
       i.Attributes["class"] = "fa fa-2x"; 
       createDiv1.ID = "createDiv" + n + 12; 
       createDiv1.Attributes["class"] = "col-md-4 col-sm-6 portfolio-item zoomIn animated"; 
       createDiv1.Attributes["data-wow-duration"] = "1500ms"; 
       createDiv1.Attributes["data-wow-delay"] = "100ms"; 
       createDiv.Attributes["class"] = "portfolio-caption"; 
       LinkButton a = new LinkButton(); 
       a.Attributes["class"] = "portfolio-link"; 
       a.Attributes["data-toggle"] = "modal"; 
       //a.Click += new EventHandler(test); 
       //a.CommandArgument = item_name; 
       /* System.Web.UI.HtmlControls.HtmlGenericControl a = new System.Web.UI.HtmlControls.HtmlGenericControl("a"); 
       a.Attributes["class"] = "portfolio-link"; 
       a.Attributes["data-toggle"] = "modal";*/ 
       System.Web.UI.HtmlControls.HtmlGenericControl h1 = new System.Web.UI.HtmlControls.HtmlGenericControl("h4"); 
       System.Web.UI.HtmlControls.HtmlGenericControl h2 = new System.Web.UI.HtmlControls.HtmlGenericControl("h4"); 
       System.Web.UI.HtmlControls.HtmlGenericControl h3 = new System.Web.UI.HtmlControls.HtmlGenericControl("h4"); 
       System.Web.UI.HtmlControls.HtmlGenericControl h4 = new System.Web.UI.HtmlControls.HtmlGenericControl("h4"); 
       System.Web.UI.HtmlControls.HtmlGenericControl h5 = new System.Web.UI.HtmlControls.HtmlGenericControl("h4"); 
       System.Web.UI.HtmlControls.HtmlGenericControl h6 = new System.Web.UI.HtmlControls.HtmlGenericControl("h4"); 





       h1.Attributes["style"] = "color:black;float: left;width: 50%; "; 
        h1.InnerHtml = "Name &nbsp &nbsp :&nbsp &nbsp " + "item_name"; 

       h2.Attributes["style"] = "color:black;float: left;width: 50%; "; 
        h2.InnerHtml = "color &nbsp &nbsp &nbsp &nbsp :&nbsp &nbsp " + "color"; 


       h3.Attributes["style"] = "color:black;float: left;width: 50%; "; 
        h3.InnerHtml = "Weight &nbsp &nbsp: &nbsp &nbsp " + "weight"; 

       h4.Attributes["style"] = "color:black;float: left;width: 50%; "; 
        h4.InnerHtml = "Quality &nbsp&nbsp: &nbsp " + "quality"; 

       h5.Attributes["style"] = "color:black;float: left;width: 50%; "; 
        h5.InnerHtml = "Clarity &nbsp&nbsp: &nbsp " + "clarity"; 

       h6.Attributes["style"] = "color:black;float: left;width: 50%; "; 
        h6.InnerHtml = "Origin &nbsp&nbsp: &nbsp " + "origin"; 

       System.Web.UI.HtmlControls.HtmlGenericControl hyp = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV"); 
       hyp.Attributes["class"] = "portfolio-link"; 

       System.Web.UI.WebControls.Image tb = new System.Web.UI.WebControls.Image() { ID = "Image" + n + 10 }; 
       tb.Height = 250; 
       tb.Width = 500; 
       tb.ImageUrl = "data:image/png;base64," /*+ Convert.ToBase64String(bytes)*/; 
       hover_content.Controls.Add(i); 
       a.Controls.Add(hover); 
       a.Controls.Add(hover_content); 
       a.Controls.Add(tb); 
       createDiv.Controls.Add(h1); 
       createDiv.Controls.Add(h2); 
       createDiv.Controls.Add(h3); 
       createDiv.Controls.Add(h4); 
       createDiv.Controls.Add(h5); 
       createDiv.Controls.Add(h6); 
       createDiv1.Controls.Add(a); 
       createDiv1.Controls.Add(createDiv); 
       // row.Controls.Add(createDiv1); 
       //section.Controls.Add(row); 

       divid1.Controls.Add(createDiv1); 
       n++; 
      } 
+0

私は同じ結果を得ました。異なる製品ラインのすべての製品の詳細を印刷します。各ラインに2つの製品が必要です。 –

+0

各見出しh1 .... h6をどこに追加しましたか教えてください。 – Bikee

+0

上記のコード全体を編集しました。親切にそれを見てください。ありがとう –