hi,
i would like to know on how to store all information to the database.
on my program i used "DataTable" to pass a certain value to the gridview controller but it doesn't store directly to the sql server database.
sample to this as shown:
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Id");
dt.Columns.Add("Name");
dt.Columns.Add("Gender");
dt.Rows.Add("1", "Sheen Buhay", "Male");
dt.Rows.Add("2", "Joji Buhay", "Female");
dt.Rows.Add("3", "Oliver Buhay", "Male");
dt.Rows.Add("4", "Elvie Buhay", "Female");
dt.Rows.Add("5", "Steve Austin", "Male");
dt.Rows.Add("6", "Alicia Keys", "Female");
DTSample = dt;
GridView1.DataSource = dt;
GridView1.DataBind();
}
this program uses gridview to auto-populate the information to the textboxes for Id, Name & Gender without any database connection.
what i would like to achieve here is i would like those data stored on the database and keep the same functionality for selecting, editing, updating directly from the gridview control.
i have a sql command on insert, delete, update however it doesn't auto-populate to the grid if i select a certain record.
i will provide the entire code for both aspx and aspx.cs extensions.
default.aspx
!--removed tag-->
!--removed tag-->
!--removed tag-->
!--removed tag-->
!--removed tag-->
!--removed tag-->
!--removed tag-->
!--removed tag-->
!--removed tag-->
default.aspx.cs
using System;
using System.Data;
using System.Web.UI;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{
public DataTable DTSample
{
get
{
DataTable table = ViewState["DTSample"] as DataTable;
return (table != null) ? table : null;
}
set
{
ViewState["DTSample"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Id");
dt.Columns.Add("Name");
dt.Columns.Add("Gender");
dt.Rows.Add("1", "Sheen Buhay", "Male");
dt.Rows.Add("2", "Joji Buhay", "Female");
dt.Rows.Add("3", "Oliver Buhay",
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).