DataKeys in Gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vajrala Narendra
    New Member
    • Jun 2007
    • 73

    DataKeys in Gridview

    Hi, all
    am working on asp.net, c# 2.0
    i want to delete a row from a grid view
    for that i take datakeyname inn gris view i wrote coding as

    Code:
    <asp:GridView ID="GridView2" runat="server" Height="72px" Width="776px" AutoGenerateColumns="False" 
                          DataKeyNames="fld_jid" >
    ----
    here fld_jid was field name which i selected in coding and bind it to gridview

    and in row deleting event i wrote
    Code:
    int jid = (int)GridView1.DataKeys[e.RowIndex].Value;
            cn.Open();
            cmd = new SqlCommand("delete from tbl_js_savedjobs where fld_jid=" + jid, cn);
            cmd.ExecuteNonQuery();
    cn.close();
    but am getting error as
    Specified cast is not valid.

    is this coding was correct or not
    please suggest me how to write
    its urgent to me

    Thanks inadvance
    Last edited by Vajrala Narendra; Oct 15 '08, 02:17 PM. Reason: nothing
  • bharathreddy
    New Member
    • Aug 2006
    • 116

    #2
    Is fld_jid an int type?.

    Comment

    • Vajrala Narendra
      New Member
      • Jun 2007
      • 73

      #3
      Originally posted by bharathreddy
      Is fld_jid an int type?.

      yes it was numeric only

      Comment

      Working...