|
this is my error
i change textbox at gridview to dropdownlist (tempaltefield)
Code:
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DB.mdb";
OleDbConnection con = new OleDbConnection(connString);
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "UPDATE Pay SET pay_sup_name=@pay_sup_name,pay_value=@pay_value,pay_check_No=@pay_check_No WHERE pay_id=@pay_id";
cmd.Parameters.Add("@pay_check_No", OleDbType.VarChar).Value = ((TextBox)PayGridView.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
cmd.Parameters.Add("@pay_value", OleDbType.VarChar).Value = ((TextBox)PayGridView.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
cmd.Parameters.Add("@pay_sup_name", OleDbType.VarChar).Value = ((DropDownList)PayGridView.Rows[e.RowIndex].Cells[4].Controls[0]).SelectedValue;
cmd.Parameters.Add("@pay_id", OleDbType.Integer).Value = Convert.ToInt32(PayGridView.Rows[e.RowIndex].Cells[1].Text);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
|
|
|
|
|
amsedky wrote: Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.TextBox
//((TextBox)PayGridView.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
Error in itself is quite straight forward.
You are directly casting controls from Grid cells into a defined type. One of the conversion is not correct. There is a Literal control instead of a textbox. A simple use of Visual Studio debugger will tell the line of code. Once you know, just handle it properly.
|
|
|
|