Hello .
I have Gridview which display a table that contain a Foreign Key , and because of
Foreign Key , The Automatic Generate Delete Link Can't be work correctly , because SqlQuery not one Table ,...

So i must Type a code in Row Delete Event ,
if my thought is False ,... please anyone Tell me the Right understand .

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id = e.RowIndex.ToString();
        SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand cmd=new SqlCommand("DELETE FROM Orders WHERE id = @id",con);
        cmd.Parameters.Add("@id",SqlDbType.Int);
        cmd.Parameters["@id"].Value=Convert.ToInt32(id);
        try
        {
            con.Open();
            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Response.Write(ex);
        }
        finally
        {
            con.Close();
        }
    }

ok , The problem is Sometimes that link (delete) Work , Sometimes not work ,
i expect the problem is about id .
So ,Please anyone Tell me what can i do ,...

Thank,...
Sorry For my Bad English :( :twisted:

Can you post your gridview markup as well? That would help to see what you are doing and what may be causing the problems.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.