if you are determined to use the datagrid for that matter, cast datagrid datasource to a datatable on button click like this :
void button_click(object sender, EventArgs e)
{
DataTable dt = (DataTable)(datagrid1.DataSource);
dt.rows.Add(new object[]{TextBox1.Text});
datagrid1.DataSource = dt;
datagrid1.DataBind();
}
alternatively you can achieve that without datagrid, using JavaScript.
You can create an html table and then add new rows to it using JavaScript. At the end, you can copy the content of the html table to an input type=hidden runat=server, and then get the values from hidden field using c#, pass all the info to the dataset and save it to database using data adapter.
The first one is easier to implement but the second prevents you from post backs and unnecessary network traffic.
|