| | |
textbox to grid
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
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 dataadapter.
The first one is more easy to implement but the second prevents you from postbacks and unneccessary network traffic.
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 dataadapter.
The first one is more easy to implement but the second prevents you from postbacks and unneccessary network traffic.
Due to lack of freedom of speech, i no longer post on this website.
![]() |
Similar Threads
- datagrid to textbox (Visual Basic 4 / 5 / 6)
- New textbox in user control broke datagrid sorting (ASP.NET)
- About how we shown a value in data grid (VB.NET)
- how to disable Copy/Cut/Paste on a textbox? (Python)
- Data grid and searching.. (Visual Basic 4 / 5 / 6)
- vb.net code to access data from Access Database (VB.NET)
- Flex Grid error "Invalid procedure call or argument" (Visual Basic 4 / 5 / 6)
- Placing a Multiline textbox over a datagrid (VB.NET)
- Grid View (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: my Silverlight is not working, why is that?
- Next Thread: sugesstion regarding ajax
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax alltypeofvideos appliances asp asp.net beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions compatible content contenttype control countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv formview gridview gudi iis javascript list listbox login menu microsoft mouse mssql nameisnotdeclared news novell numerical opera order panelmasterpagebuttoncontrols problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security serializesmo.table sessionvariables silverlight smoobjects software sql sql-server sqlserver2005 ssl tracking treeview validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming webservice wizard xsl






