Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two textbox,want to enter values in this. then this value have to add values in datagrid.
Posted

You need to try something like this

C#
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
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900