2016-04-10 27 views
1

Resimde dinamik olarak galeride görüntüleniyor, aşağıdaki resim i ürün adı, ürün ağırlığı, ürün rengi, ürün kalitesi, kökeni ve miktarı. Şu anda 6 satırda görüntüleniyor, Satır başına her öğe ... Her satırda iki öğe ve 3 satırda 6 öğe görüntülemek istiyorum.İlk öğe sola, ikinci öğeyi sağa ilk satırda hizalanmalı ve böyle devam etmelidir. Nasıl yapabilirim? bu benim kodum. Aynı satırda sol ve sağa hizalama dinamik olarak 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) 
 
    { 
 

 
    } 
 
}

Güncelleme Kod Bro kodunuzu çalışmadı. Bu şekilde denedim, bir şekilde çalışıyor. H1 solda H2, sağda H2 gösterir. Ayrıca bir sonraki satırda olması gerektiği gibi ortada da h3'ü gösterir. Bunu çözebilirim.

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

Bu h2.Attributes yaptığınızda [ "align"] = "Sağ", h2.Attributes (benim VS ayarlanması için değişkenleri göz Yorumlananlar) [ "align "] =" SOL "kaybolur. –

cevap

0

kullanın Aşağıdaki kodu. Öznitelikleri ["align"] = "SOL" bölümünü kaldırdım ve float: left; width: 50%;. İhtiyaçlarınıza göre genişlik yüzdesini ayarlayın.

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; 

GÜNCELLEME

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

hala aynı sonucu aldım. Her ürün detayını farklı hatlarda basıyor. Her bir satırda iki ürün istiyorum. –

+0

Her başlığı h1 .... h6 olarak nereye eklediğinizi söyler misiniz? – Bikee

+0

Yukarıdaki kodun tamamını düzenledim. Lütfen görüyorum.Teşekkürler –

İlgili konular