How to add rows and insert data in datagridview C#
Can someone help me ?
i want datagridview display data
datagridview1.datasource = _db.Students.Tolist();
and it display on data grid. and has a button.if the button click, datagridview1 will add the rows with no data开发者_如何转开发. And the User fill the rows. when it done it will save to database.
How to make it work ?
If I remember correctly, DataGridView has a .Rows.Add property, like this:
dataGridView.Rows.Add
and
dataGridView.Rows.Insert
You should convert your data into an array first.
Take a look here: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows.aspx
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "createNewRecord")
{
//Another Gridview will be created here, and it will contains EditTemplate.
//you can use that gridview to receive data by Edit.
}
}
Sample of Edit tamplate gridview
<Columns>
<asp:TemplateField>
<EditItemTemplate><asp:textboxt id="txt1" runat="server" /></EditItemTemplate>
</asp:TemplateField>
</Columns>
精彩评论