您将如何从 gridview 更新 SQL 数据库?(更新记录后)
使用 - SharePoint -> 应用程序页面 - 我知道,SharePoint....“让基本的事情变得更基本,让困难的事情变得不可能”(侧面甚至没有 SQLDatasource 控件,如果需要,您必须自己添加它- 不知道他们是否不想让您在项目中添加一个或其他东西......)
我在 gridview 中显示了数据,并启用了
AutoGenerateEditButton="True"
在网格视图中。gridview 的数据源是我从数据库中填充的数据集。
我认为如果没有绑定到您的网格视图的 SQLDatasource,您将不得不再次连接到数据库并手动更新数据库。但是除了绑定到自动更新的gridview的SQLDataSource之外,我似乎找不到任何方法来做到这一点。
执行此操作的方法,但需要绑定到 gridview 的 SQLDatasource
编辑 gridview 后,您将如何更新数据库?
--更新解决方案--添加了一些修改。谢谢
protected void Page_Load(object sender, EventArgs e)
{
int employeerId = 1;
//Add all the employees to the list to view them.
string query = "select emp.Name as [Employee Name], em.* from EthicsManagement em join EmployeeTable emp on em.employeeId = emp.employeeId where emp.managerId =" + employeerId;
DataSet ds = dbConn.returnSqlDataset(query);
grdViewDetails.DataSource = ds;
grdViewDetails.DataBind();
int x = grdViewDetails.Columns.Count;
//Hide the columns.
grdViewDetails.DataBind();
if (grdViewDetails.Columns.Count > 0)
{
grdViewDetails.Columns[2].Visible = false;
grdViewDetails.Columns[3].Visible = false;
}
else
{
grdViewDetails.HeaderRow.Cells[0].Visible = false;
foreach (GridViewRow gvr in grdViewDetails.Rows)
{
gvr.Cells[2].Visible = false;
gvr.Cells[3].Visible = false;
}
}
}
protected void grdViewDetails_RowEditing1(object sender, GridViewEditEventArgs e)
{
string query = "select emp.Name as [Employee Name], em.* from EthicsManagement em join EmployeeTable emp on em.employeeId = emp.employeeId where emp.managerId =" + 1;
grdViewDetails.EditIndex = e.NewEditIndex;
//e.newedit index:- will be provide index of row for which edit button is selected
grdViewDetails.DataSource = dbConn.returnSqlDataset(query);
grdViewDetails.DataBind();
}
protected void grdViewDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string query = "select emp.Name as [Employee Name], em.* from EthicsManagement em join EmployeeTable emp on em.employeeId = emp.employeeId where emp.managerId =" + 1;
foreach (TableCell cell in grdViewDetails.Rows[e.RowIndex].Cells)
{
if (cell.Controls[0] is TextBox)
{
TextBox textbox = (TextBox)cell.Controls[0];
string value = textbox.Text;
}
else
{
if (cell.Controls[0] is CheckBox)
{
CheckBox chkBoxWeek = (CheckBox)cell.Controls[0];
Boolean checkStatus = chkBoxWeek.Checked;
}
}
}