有一张数据库表,里面是控件TextBox的Id名称,行号和列号tableATextBoxName   Row    columns
TextBox1
TextBox2
TextBox3
TextBox4
TextBox5
TextBox6
TextBox7
TextBox8
TextBox9
TextBox10
TextBox11
TextBox12
TextBox13
TextBox14
TextBox15我想要这样一个效果:在一个页面上可以设置这些TextBox控件的行号和列号,比如一个页面,左半边以radiobuttonlist的方式显示这些TextBox控件,右半边以20乘以20的方格的形式显示400个按钮,接下来,比如要设置TextBox1的行号和列号,只要先在页面的左半边选中这个控件然后在页面的右半边的方格中选择一个按钮(坐标),然后点击页面上的设置按钮要实现这个方法可能会比较复杂和麻烦,像这样的方法叫什么名称?有现成的源代码吗?我要搜索的话,应该以什么样的关键字搜索才能搜索到这样的源代码?

解决方案 »

  1.   

    根据名字找控件  Page.FindControl("")
      

  2.   

    protected void Page_Load(object sender, EventArgs e)
            {
                Table tb = new Table();
                for (int i = 0; i < 20; i++)
                {
                    TableRow row = new TableRow();
                    for (int j = 0; j < 20; j++)
                    { 
                        TableCell cell = new TableCell();
                        Button bt = new Button();
                        bt.ID = string.Format("bt{0}_{1}", i, j);
                        bt.Text = string.Format("{0}行{1}列", i, j);
                        bt.Click += new EventHandler(bt_Click);
                        cell.Controls.Add(bt);
                        row.Cells.Add(cell);
                    }
                    tb.Rows.Add(row);
                }            this.Controls.Add(tb);
            }        void bt_Click(object sender, EventArgs e)
            {
                Button bt = sender as Button;
                string[] tmp = bt.ID.Replace("bt", string.Empty).Split('_');
                int row = int.Parse(tmp[0]);//行
                int col = int.Parse(tmp[1]);//列            //后面该怎么数据库操作就怎么操作
            }
      

  3.   

    4楼正解,不过需要将table添加到form中,this.form1.Controls.Add(tb)
      

  4.   

    如果是GridView的模板方式,你不要妄加判断下  ItemTemplate 的模式
      

  5.   

    你写的这个我已经实现了,问题是第2次打开这个页面的时候要求页面的右半边的20乘以20的方格中相对应地显示已经设置好行号和列号的Textbox控件ID名称,这个我不会
      

  6.   

    你把bt.Text = string.Format("{0}行{1}列", i, j);这段改下就可以了啊
    你都知道行列了,也知道数据库对应的行列
    判断当 
    if(行相等&&列相等)
    {
       //text就显示为已设置的bttext
    }用linq的话
    假设你的数据库读出来的数据对应的实体集合为 List<BtEntity> list
    BtEntity entity = list.Where(e=>e.Row == i && e.Column = j).FirstOrDefault();
    if(entity!=null)
    {
       //text = entity.Text
    }
      

  7.   

    Page.FindControl("")