Becky Bloomwood

Becky Bloomwood

  • NA
  • 119
  • 285.5k

Convert textbox in gridview to accept value that are of datetime and deimal into database

Feb 14 2011 10:30 PM

Hi, I have try convert sqldatetime and decimal datatype to string such that the textbox is able to enter datetime value.But there is an error.
This is my code:
 

protected void gvContract_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DateTime startDate = Convert.ToDateTime(gvContract.DataKeys[e.RowIndex].Value.ToString());
DateTime endDate = Convert.ToDateTime(gvContract.DataKeys[e.RowIndex].Value.ToString());
decimal amount = Convert.ToDecimal(gvContract.DataKeys[e.RowIndex].Value.ToString());

Label txtContractID = (Label)gvContract.Rows[e.RowIndex].FindControl("txtContractID");
TextBox txtEmpName = (TextBox)gvContract.Rows[e.RowIndex].FindControl("txtEmpName");
TextBox txtStartDate = (TextBox)gvContract.Rows[e.RowIndex].FindControl("txtStartDate");
TextBox txtEndDate = (TextBox)gvContract.Rows[e.RowIndex].FindControl("txtEndDate");
TextBox txtAmount = (TextBox)gvContract.Rows[e.RowIndex].FindControl("txtAmount");
TextBox txtVendorBrn = (TextBox)gvContract.Rows[e.RowIndex].FindControl("txtVendorBrn");
TextBox txtName = (TextBox)gvContract.Rows[e.RowIndex].FindControl("txtName ");
TextBox txtProducts = (TextBox)gvContract.Rows[e.RowIndex].FindControl("txtProducts ");
TextBox txtRef = (TextBox)gvContract.Rows[e.RowIndex].FindControl("txtRef");
TextBox txtProj = (TextBox)gvContract.Rows[e.RowIndex].FindControl("txtPro ");
TextBox txtAlert = (TextBox)gvContract.Rows[e.RowIndex].FindControl("txtAlert");
TextBox txtTemplateID = (TextBox)gvContract.Rows[e.RowIndex].FindControl("txtTemplateID ");

vrmdb.Update_ContractRecords(txtContractID.Text, txtEmpName.Text,txtStartDate.Text, txtEndDate.Text, txtAmount.Text,txtVendorBrn.Text,txtName.Text,txtProducts.Text,txtRef.Text, txtProj.Text,txtAlert.Text,txtTemplateID.Text);
gvContract.EditIndex = -1;
BindGrid(
true);
Response.Redirect(
"ContractManagement.aspx");
}
}
}
May I know how to convert the textbox such that they are able to accpet value that are of datetime and decimal. Thks!

Answers (9)