I have a gridview in which I want my client to be able to edit and add information. I am getting an error on updates as well as adding the records.
I am getting the following error for edit:
I am getting the id, but not the control, or the information from the control. The controls are templatefields, how can I pull the value from the template fields?
I have the following (my delete statement is fine:
I am getting the following error for edit:
Code:
There was an error updating the information for record
224
System.NullReferenceException: Object reference not set to an instance of an object. at InventoryGrid.showVal(Object sender, GridViewCommandEventArgs e) in c:\Inetpub\[URL unfurl="true"]wwwroot\BETInventoryTest\InventoryGrid.aspx.cs:line[/URL] 266
I am getting the id, but not the control, or the information from the control. The controls are templatefields, how can I pull the value from the template fields?
I have the following (my delete statement is fine:
Code:
protected void showVal(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DeleteRow")
{
string index = e.CommandArgument.ToString();
lblNotify.Text = "You have selected Record" + index + "to delete. This is a permanent action.";
int rowtoDelete = Convert.ToInt32(index);
//begin process to delete
try
{
//delete inventory based on stored procedure
lblNotify.Text = "You are about to Delete " + rowtoDelete + ".";
string dc = ConfigurationManager.ConnectionStrings["SiteDB"].ConnectionString;
SqlConnection dconn = new SqlConnection(dc);
SqlCommand dcomm = new SqlCommand("testDelete", dconn);
dcomm.CommandType = CommandType.StoredProcedure;
dcomm.Parameters.AddWithValue("@RemoveID", rowtoDelete);
dcomm.Connection.Open();
dcomm.ExecuteNonQuery();
lblNotify.Text = "You selected successfully deleted record " + rowtoDelete;
dcomm.Connection.Close();
iGrid.EditIndex = -1;
iGrid.DataBind();
}
catch (Exception deleteError)
{
lblNotify.Text = "Error on deleting record" + deleteError;
}
}
else if (e.CommandName == "editRec")
{
string eindex = e.CommandArgument.ToString();
int rowtoEdit = Convert.ToInt32(eindex);
lblNotify.Text = "You have selected Record" + eindex + " to edit.";
//update Inventory
try
{
int intbuilding;
int intCubicle;
int intOffice;
int intCafe;
int intConferencerm;
int intLobby;
int intFloor;
int intDepart;
int intEquipment;
int intEquipType;
string strModel;
string strSerial;
string strCubicleN;
string strOfficeN;
int locationtypes;
string roomnum;
string comments;
string otherLocation;
//use the following to test;
foreach (GridViewRow row in iGrid.Rows)
{
DropDownList buil = (DropDownList)row.FindControl("drpBuilding");
lblNotify.Text = buil.SelectedValue;
}
//original
//DropDownList ubldg = (DropDownList)iGrid.FindControl("drpBuilding");