我有两个文本框,想要在其中输入值.那么该值必须在datagrid中添加值. [英] I have two textbox,want to enter values in this. then this value have to add values in datagrid.

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

问题描述

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

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

推荐答案


您需要尝试这样的事情

You need to try something like this

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


尝试使用数据表,-

Try to do with datatable,-

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中添加值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆