data gridview tasks
i have msaccess database
i am working for website in asp using C#
i use datagrid for db conectivity &also enable edit and DELETE from it
now i want to add new data to datagrid
which may b possile by enable adding
but the problem is that it is not been showing in task bar
i am using VISUAL STUDIO 2005
please solve my problem
Status:
Open Mar 05, 2009 - 11:48 PM
category2
3answers
Answers
Mar 08, 2009 - 01:40 AM
What you can do is create a new datarow and add that to a datatable. That then goes to a dataview which you associate to the datagrid. This example is in vb.net but it should be easy enough to translate to c#
Ive added comments in to help you out
'Define a datatable, datarow and dataview
Dim dt As DataTable
Dim dr As DataRow
Dim dw As DataView
'Associate the currnt datasource to the data table
dt = DataGrid1.DataSource
'Create a new row
dr = dt.NewRow()
'Populate the fields in that datatable
dr("ID") = "100"
dr("MyValue") = "Quomon"
'Add this new DataRow to the DataTable
dt.Rows.Add(dr)
'Now add that DataTable to a new instance of a DataView
dw = New DataView(dt)
'And finally add that dataview to the DataGrid datasource
DataGrid1.DataSource = dw
Mar 08, 2009 - 01:42 AM
I think this is the c# equivalent
It assumes u have a datagrid control called dataGrid1
and datasource has 2 columns ID and MyValue
DataTable dt;
DataRow dr;
dt = DataGrid1.DataSource;
dr = dt.NewRow();
dr("ID") = "100"
dr("MyValue") = "Quomon"
dt.Rows.Add(dr)
DataView dw = new DataView(dt);
dataGrid1.DataSource = dw;
Apr 06, 2009 - 03:01 AM
The question looks to be abandoned by the user who asked it. If no action is taken within 2 days, a Quomon Moderator will consider closing the question and distributing the points.
The Quomon Team
Answer this question
Share Your Own Experience & Expertise
We look to ensure that every question is answered by the best people with relevant expertise and experience, the best answers include multiple perspectives. Do you have relevant expertise or experience to contribute your answer to any of these commonly asked questions?
Add New Comment