protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
try
{
TextBox T1 = GridView1.FooterRow.FindControl("NewProductLocation") as TextBox;
TextBox T2 = GridView1.FooterRow.FindControl("NewDepartment") as TextBox;TextBox T3 = GridView1.FooterRow.FindControl("NewPurchase_Date") as TextBox;
TextBox T4 = GridView1.FooterRow.FindControl("NewHardware_Type") as TextBox;TextBox T5 = GridView1.FooterRow.FindControl("NewSerial_Number") as TextBox;
TextBox T6 = GridView1.FooterRow.FindControl("NewModel") as TextBox;TextBox T7 = GridView1.FooterRow.FindControl("NewAsset_Tag") as TextBox;
TextBox T8 = GridView1.FooterRow.FindControl("NewOperation_System") as TextBox;TextBox T9 = GridView1.FooterRow.FindControl("NewPrice") as TextBox;
TextBox T10 = GridView1.FooterRow.FindControl("NewComments") as TextBox;TextBox T11 = GridView1.FooterRow.FindControl("NewManufacture") as TextBox;Console.WriteLine(T1);
int i = GridView1.SelectedIndex;SqlParameter index = new SqlParameter("@i", SqlDbType.NVarChar, 50);index.Direction = ParameterDirection.Input;
insertParameters.Add(index);
SqlParameter location = new SqlParameter("@T1", SqlDbType.VarChar, 50);location.Direction = ParameterDirection.Input;
location.Value = T1.Text;
insertParameters.Add(location);
SqlParameter department = new SqlParameter("@T2", SqlDbType.VarChar, 100);department.Direction = ParameterDirection.Input;
department.Value = T2.Text;
insertParameters.Add(department);
SqlParameter PurchaseDate = new SqlParameter("@T3", SqlDbType.DateTime);PurchaseDate.Direction = ParameterDirection.Input;
PurchaseDate.Value = T3.Text;
insertParameters.Add(PurchaseDate);
SqlParameter HardwareType = new SqlParameter("@T4", SqlDbType.VarChar, 50);HardwareType.Direction = ParameterDirection.Input;
HardwareType.Value = T4.Text;
insertParameters.Add(HardwareType);
SqlParameter SerialNumber = new SqlParameter("@T5", SqlDbType.VarChar, 50);SerialNumber.Direction = ParameterDirection.Input;
SerialNumber.Value = T5.Text;
insertParameters.Add(SerialNumber);
SqlParameter Model = new SqlParameter("@T6", SqlDbType.VarChar, 200);Model.Direction = ParameterDirection.Input;
Model.Value = T6.Text;
insertParameters.Add(Model);
SqlParameter AssetTag = new SqlParameter("@T7", SqlDbType.VarChar, 50);AssetTag.Direction = ParameterDirection.Input;
AssetTag.Value = T7.Text;
insertParameters.Add(AssetTag);
SqlParameter OperatingSystem = new SqlParameter("@T8", SqlDbType.VarChar, 50);OperatingSystem.Direction = ParameterDirection.Input;
OperatingSystem.Value = T8.Text;
insertParameters.Add(OperatingSystem);
SqlParameter Price = new SqlParameter("@T9", SqlDbType.Decimal);Price.Direction = ParameterDirection.Input;
Price.Value = T9.Text;
insertParameters.Add(Price);
SqlParameter comments = new SqlParameter("@T10", SqlDbType.VarChar, 500);comments.Direction = ParameterDirection.Input;
comments.Value = T10.Text;
insertParameters.Add(comments);
SqlParameter manufacture = new SqlParameter("@T11", SqlDbType.VarChar, 200);manufacture.Direction = ParameterDirection.Input;
manufacture.Value = T11.Text;
insertParameters.Add(manufacture);
SqlDataSource1.Insert();
}
catch (NullReferenceException ne)
{
Console.WriteLine("{0} Caught exception #1.", ne);
}
Null values are getting inserted. can somebody please help me out.
thanks.
akhil