Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > สอบถาม code ที่กดปุ่ม แล้วเพิ่ม control ตัวหนึ่งๆได้เรื่อยๆ คล้ายกับการ browe รูป ที่มีป่มหนึ่งแล้วกดให้มีช่องเพ่ิมได้เรื่อยๆน่ะคะ



 

สอบถาม code ที่กดปุ่ม แล้วเพิ่ม control ตัวหนึ่งๆได้เรื่อยๆ คล้ายกับการ browe รูป ที่มีป่มหนึ่งแล้วกดให้มีช่องเพ่ิมได้เรื่อยๆน่ะคะ

 



Topic : 066480



โพสกระทู้ ( 34 )
บทความ ( 0 )



สถานะออฟไลน์




ตามหัวข้อเลยค่ะ ไม่ทราบว่า ใช้ jquery หรือ อื่นๆ ที่สามารถทำให้เพิ่มตัว control ได้น่ะค่ะ คืออยากเพิ่ม dropdownlist น่ะค่ะ คือก่อนหน้านี้จะมี

dropdownlist ตัวหนึ่งอยู่ก่อน ซึ่งให้เลือกรายวิชา แล้วด้านข้างก็จะมีปุ่มกดให้เพิ่มรายวิชาได้ แล้วที่นี้พอกดปุ่มนี้อยากให้มี dropdownlist ที่

เหมือนตัวข้างบนเพิ่มขึ้นมาข้างล่าง พอกดเพิ่มอีกก็เพิ่มไปเรื่อยๆน่ะค่ะ ไม่ทราบว่าจะต้องเขียนประมาณไหน



Tag : .NET, Ajax, jQuery, Web (ASP.NET), C#, VS 2008 (.NET 3.x)









ประวัติการแก้ไข
2011-09-13 18:33:20
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-09-13 18:08:58 By : kpnm View : 939 Reply : 2
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ไม่ยากครับ ใช้ Control.Add ในการสร้าง Create New Control ขึ้นมาใหม่ได้ครับ


Go to : (C#) ASP.NET Controls.Add






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-09-16 09:31:05 By : webmaster
 


 

No. 2



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code (C#)
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
   <script runat="server" >

      void Selection_Change(Object sender, EventArgs e)
      {

         // Retrieve the DropDownList control from the Controls  
         // collection of the PlaceHolder control.
         DropDownList DropList = 
             (DropDownList)Place.FindControl("ColorList"); 

         // Set the background color for days in the Calendar control
         // based on the value selected by the user from the 
         // DropDownList control.
         Calendar1.DayStyle.BackColor = 
             System.Drawing.Color.FromName(DropList.SelectedItem.Value);

      }

      void Page_Load(Object sender, EventArgs e)
      {

         // Create a DropDownList control.
         DropDownList DropList = new DropDownList();

         // Set the properties for the DropDownList control.
         DropList.ID = "ColorList";
         DropList.AutoPostBack = true;

         // Manually register the event-handling method for the 
         // SelectedIndexChanged event.
         DropList.SelectedIndexChanged += 
             new EventHandler(this.Selection_Change);

         // Because the DropDownList control is created dynamically each
         // time the page is loaded, the data must be bound to the
         // control each time the page is refreshed.

         // Specify the data source and field names for the Text and 
         // Value properties of the items (ListItem objects) in the
         // DropDownList control.
         DropList.DataSource = CreateDataSource();
         DropList.DataTextField = "ColorTextField";
         DropList.DataValueField = "ColorValueField";

         // Bind the data to the control.
         DropList.DataBind();

         // Set the default selected item when the page is first loaded.
         if(!IsPostBack)
         {  
            DropList.SelectedIndex = 0;
         }

         // Add the DropDownList control to the Controls collection of 
         // the PlaceHolder control.
         Place.Controls.Add(DropList);

      }

      ICollection CreateDataSource() 
      {

         // Create a table to store data for the DropDownList control.
         DataTable dt = new DataTable();

         // Define the columns of the table.
         dt.Columns.Add(new DataColumn("ColorTextField", typeof(String)));
         dt.Columns.Add(new DataColumn("ColorValueField", typeof(String)));

         // Populate the table with sample values.
         dt.Rows.Add(CreateRow("White", "White", dt));
         dt.Rows.Add(CreateRow("Silver", "Silver", dt));
         dt.Rows.Add(CreateRow("Dark Gray", "DarkGray", dt));
         dt.Rows.Add(CreateRow("Khaki", "Khaki", dt));
         dt.Rows.Add(CreateRow("Dark Khaki", "DarkKhaki", dt));

         // Create a DataView from the DataTable to act as the data source
         // for the DropDownList control.
         DataView dv = new DataView(dt);
         return dv;

      }

      DataRow CreateRow(String Text, String Value, DataTable dt)
      {

         // Create a DataRow using the DataTable defined in the 
         // CreateDataSource method.
         DataRow dr = dt.NewRow();

         // This DataRow contains the ColorTextField and ColorValueField 
         // fields, as defined in the CreateDataSource method. Set the 
         // fields with the appropriate value. Remember that column 0 
         // is defined as ColorTextField, and column 1 is defined as 
         // ColorValueField.
         dr[0] = Text;
         dr[1] = Value;

         return dr;

      }

   </script>

<head runat="server">
    <title> DropDownList Constructor Example </title>
</head>
<body>

   <form id="form1" runat="server">

      <h3> DropDownList Constructor Example </h3>

      Select a background color for days in the calendar.

      <br /><br /> 

      <asp:Calendar id="Calendar1"
           ShowGridLines="True" 
           ShowTitle="True"
           runat="server"/>

      <br /><br />

      <table cellpadding="5">

         <tr>

            <td>

               Background color:

            </td>

         </tr>

         <tr>

            <td>

               <asp:PlaceHolder id="Place"
                    runat="server"/>

            </td>

         </tr>

      </table>   

   </form>

</body>
</html>


ลองดู Code นี้ครับ ตรง

Code (C#)
void Page_Load(Object sender, EventArgs e)
      {

         // Create a DropDownList control.
         DropDownList DropList = new DropDownList();

         // Set the properties for the DropDownList control.
         DropList.ID = "ColorList";
         DropList.AutoPostBack = true;

         // Manually register the event-handling method for the 
         // SelectedIndexChanged event.
         DropList.SelectedIndexChanged += 
             new EventHandler(this.Selection_Change);

         // Because the DropDownList control is created dynamically each
         // time the page is loaded, the data must be bound to the
         // control each time the page is refreshed.

         // Specify the data source and field names for the Text and 
         // Value properties of the items (ListItem objects) in the
         // DropDownList control.
         DropList.DataSource = CreateDataSource();
         DropList.DataTextField = "ColorTextField";
         DropList.DataValueField = "ColorValueField";

         // Bind the data to the control.
         DropList.DataBind();

         // Set the default selected item when the page is first loaded.
         if(!IsPostBack)
         {  
            DropList.SelectedIndex = 0;
         }

         // Add the DropDownList control to the Controls collection of 
         // the PlaceHolder control.
         Place.Controls.Add(DropList);

      }

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-09-16 09:32:17 By : webmaster
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถาม code ที่กดปุ่ม แล้วเพิ่ม control ตัวหนึ่งๆได้เรื่อยๆ คล้ายกับการ browe รูป ที่มีป่มหนึ่งแล้วกดให้มีช่องเพ่ิมได้เรื่อยๆน่ะคะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่