|
|
|
ต้องการสร้าง textbox, dropdownlist ใน table cell คอลัมน์ที่ต้องการ โดยรับค่าจำนวนตามที่ใส่ |
|
|
|
|
|
|
|
Code ใน cs ครับ
Code (C#)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
List<TextBox> ArrayTextBox;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
CreateTextBox();
int nrows;
int ncells;
//int numrows;
//int numcells;
int i = 0;
int j = 0;
TableRow r;
TableCell c;
// Generate rows and cells
nrows = Convert.ToInt32(this.txtRow.Text);
ncells = Convert.ToInt32(this.txtCell.Text);
//numrows = Convert.ToInt32(DropDown1.SelectedItem.Value);
//numcells = Convert.ToInt32(DropDown2.SelectedItem.Value);
for (j = 0; j <= nrows - 1; j++)
{
r = new TableRow();
for (i = 0; i <= ncells - 1; i++)
{
c = new TableCell();
TextBox aTextBox = new TextBox();
//aTextBox.ID = "aTextBox" + i.ToString();
//c.Controls.Add(aTextBox);
//c.Controls.Add(new LiteralControl("row " + j + ", cell " + i));
c.Controls.Add(aTextBox);
r.Cells.Add(c);
}
Table1.Rows.Add(r);
}
} //ปิด class Button1_Click
protected void CreateTextBox()
{
if (txtNumText.Text != ""){
int count = int.Parse(txtNumText.Text);
if (count > 0){
ArrayTextBox = new List<TextBox>();
for (int i = 0; i < count; i++)
{
TextBox aTextBox = new TextBox();
aTextBox.ID = "aTextBox" + i.ToString();
ArrayTextBox.Add(aTextBox);
RequiredFieldValidator aRequiredFieldValidator = new RequiredFieldValidator();
aRequiredFieldValidator.ControlToValidate = "aTextBox" + i.ToString();
aRequiredFieldValidator.ErrorMessage = "*";
PlaceHolder1.Controls.Add(aTextBox);
//PlaceHolder1.Controls.Add(aRequiredFieldValidator);
PlaceHolder1.Controls.Add(new LiteralControl(@"<br />"));
}
//Button ButtonShow = new Button();
//ButtonShow.Text = "Show";
//ButtonShow.Click += new EventHandler(ButtonShow_Click);
//PlaceHolder1.Controls.Add(ButtonShow);
//TextBox1.ReadOnly = true;
//Button1.Enabled = false;
} //ปิด if Count
} //ปิด if txtNumText
} // ปิด class CreateTextBox
} //ปิด public class _Default
} //ปิด namespace
|
|
|
|
|
Date :
2016-11-14 11:54:09 |
By :
mhoobin |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|