Hi all,
I'm trying to update a SQL Row based on the value of a column in the DataGrid. Everything works fine as long as the column is not hidden. When I set the Visible attribute to false on the column I receive an error at runtime because the Update command fails due to the value of the hidden column being set to nulls.
Does anyone know how I can accomplish hidding the column and capture the value?
Here's part of my code:
<asp:BoundColumn Visible="False" DataField="Emp Contact ID"></asp:BoundColumn>
C# Code:
private void myDataGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
System.Web.UI.WebControls.TextBox cEmail = new System.Web.UI.WebControls.TextBox();
System.Web.UI.WebControls.TextBox cID = new System.Web.UI.WebControls.TextBox();
cEmail = (System.Web.UI.WebControls.TextBox) e.Item.Cells[2].Controls[0];
cID = (System.Web.UI.WebControls.TextBox) e.Item.Cells[6].Controls[0];
SqlCommand myCommand = new SqlCommand("IntranetEmpContactUPD",myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add(new SqlParameter("@Email",SqlDbType.VarChar,30));
myCommand.Parameters["@Email"].Value = cEmail.Text;
myCommand.Parameters.Add(new SqlParameter("@EmpContactID",SqlDbType.Int));
myCommand.Parameters["@EmpContactID"].Value = Convert.ToInt32(cID.Text);
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
myDataGrid.EditItemIndex = -1;
BindData();
I'm trying to update a SQL Row based on the value of a column in the DataGrid. Everything works fine as long as the column is not hidden. When I set the Visible attribute to false on the column I receive an error at runtime because the Update command fails due to the value of the hidden column being set to nulls.
Does anyone know how I can accomplish hidding the column and capture the value?
Here's part of my code:
<asp:BoundColumn Visible="False" DataField="Emp Contact ID"></asp:BoundColumn>
C# Code:
private void myDataGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
System.Web.UI.WebControls.TextBox cEmail = new System.Web.UI.WebControls.TextBox();
System.Web.UI.WebControls.TextBox cID = new System.Web.UI.WebControls.TextBox();
cEmail = (System.Web.UI.WebControls.TextBox) e.Item.Cells[2].Controls[0];
cID = (System.Web.UI.WebControls.TextBox) e.Item.Cells[6].Controls[0];
SqlCommand myCommand = new SqlCommand("IntranetEmpContactUPD",myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add(new SqlParameter("@Email",SqlDbType.VarChar,30));
myCommand.Parameters["@Email"].Value = cEmail.Text;
myCommand.Parameters.Add(new SqlParameter("@EmpContactID",SqlDbType.Int));
myCommand.Parameters["@EmpContactID"].Value = Convert.ToInt32(cID.Text);
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
myDataGrid.EditItemIndex = -1;
BindData();