Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,



I am getting error in datagrid.First I has created a datatable.Then I added rows and columns.Then I have to bound it into datagrid.I am not getting the values in datagrid.Plz help me.Below is a code.

private void button1_Click(object sender, System.EventArgs e)
        {
            DataTable table1;
            DataRow row1, row2, row3, row4;
            table1 = new DataTable("Customers");

            DataColumn firstName = new DataColumn("First Name");
            firstName.DataType = System.Type.GetType("System.String");
            table1.Columns.Add(firstName);

            DataColumn lastName = new DataColumn("Last Name");
            lastName.DataType = System.Type.GetType("System.String");
            table1.Columns.Add(lastName);

            DataColumn phone = new DataColumn("Phone");
            phone.DataType = System.Type.GetType("System.String");
            table1.Columns.Add(phone);

            DataColumn id = new DataColumn("ID");
            id.DataType = System.Type.GetType("System.Int32");
            table1.Columns.Add(id);

            row1 = table1.NewRow();

            row1["First Name"] = "A";
            row1["Last Name"] = "B";
            row1["Phone"] = "(555) 333-4444";
            row1["ID"] = 1;

            table1.Rows.Add(row1);

            row2 = table1.NewRow();

            row2["First Name"] = "B";
            row2["Last Name"] = "C";
            row2["Phone"] = "(555) 333-4445";
            row2["ID"] = 2;

            table1.Rows.Add(row2);

            row3 = table1.NewRow();

            row3["First Name"] = "E";
            row3["Last Name"] = "R";
            row3["Phone"] = "(555) 333-4445";
            row3["ID"] = 3;

            table1.Rows.Add(row3);

            row4 = table1.NewRow();

            row4["First Name"] = "W";
            row4["Last Name"] = "K";
            row4["Phone"] = "(555) 333-4447";
            row4["ID"] = 4;

            table1.Rows.Add(row4);

            DataSet dataset1 = new DataSet();
            dataset1.Tables.Add(table1);
            dataGrid1.SetDataBinding(dataset1, "Customers");
        }
  }


I am getting error in the lastline " datagrid does not contain a definition for SetDataBinding" occurs.Plz help me
Posted

1 solution

try this if you want to bind your dataset to DataGrid

dataGrid1.DataSource=dataset1.Tables[0] ;
 
Share this answer
 
v2

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