本文介绍了我有两个文本框,想要在其中输入值.那么该值必须在datagrid中添加值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文本框,想要在其中输入值.那么该值必须在datagrid中添加值.

I have two textbox,want to enter values in this. then this value have to add values in datagrid.

推荐答案


int x;
           int y;
           try
           {
               int.TryParse(textBox1.Text, out x);
               int.TryParse(textBox2.Text, out y);
               //Then depending on if you want to add row to grid or update cell in grid
               dataGrid1.Rows.Add(new int[] { x, y });
               //or
               dataGrid1.Cells[0] = x;
               dataGrid1.Cells[1] = y;
           }
           catch (ArgumentException)
           {
               MessageBox.Show("One of your text boxes does not contain an integer.");
           }



希望对您有所帮助



Hope this helps


DataTable dt = new DataTable();
            dt.Columns.Add("Name");
            dt.Columns.Add("Address");

DataRow aRow;
aRow = dt.NewRow();
                aRow["Name"] = txtName.text;
                aRow["Address"] = txtAddress.Text;

dt.Rows.Add(aRow);

Gridview1.Datasource=dt;
GridView1.Databind();</pre>

If u want to perform this operation for multiple column then try with loop.


这篇关于我有两个文本框,想要在其中输入值.那么该值必须在datagrid中添加值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 22:11