C# - DataGrid - Use Hidden Column to Update SQL Row

Joined
Nov 7, 2006
Messages
1
Reaction score
0
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();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top