Reputation: 1489
I want to delete the row of gridview. So i added Commandfield Delete button for all rows. When i click to delete button, it triggers gvBooklist_RowDeleting
event. In that i'm giving the following code to get current book name.
string tempBook = gvBooklist.Rows[e.RowIndex].Cells[0].ToString();
SqlCommand cmd = new SqlCommand("Select id from tBooks where bookName = '" + tempBook + "';");
But tempBook returns System.Web.UI.WebControls.DataControlFieldCell
. How do i get the actual book name?
Upvotes: 0
Views: 4793
Reputation: 460360
Instead of ToString
use it's Text
property:
string tempBook = gvBooklist.Rows[e.RowIndex].Cells[0].Text;
Side note: you also should use sql-parameters - always:
using(var cmd = new SqlCommand("Select id from tBooks where bookName = @bookname"))
{
cmd.Parameters.Add("@bookname", SqlDbType.VarChar).Value = tempBook;
// ...
}
Upvotes: 5