473,327 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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

Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="GridView2" runat="server" Height="72px" Width="776px" AutoGenerateColumns="False" 
  2.                       DataKeyNames="fld_jid" >
  3. ----
here fld_jid was field name which i selected in coding and bind it to gridview

and in row deleting event i wrote
Expand|Select|Wrap|Line Numbers
  1. int jid = (int)GridView1.DataKeys[e.RowIndex].Value;
  2.         cn.Open();
  3.         cmd = new SqlCommand("delete from tbl_js_savedjobs where fld_jid=" + jid, cn);
  4.         cmd.ExecuteNonQuery();
  5. 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
Oct 15 '08 #1
2 1292
bharathreddy
111 100+
Is fld_jid an int type?.
Oct 15 '08 #2
Is fld_jid an int type?.

yes it was numeric only
Oct 15 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Lingo | last post by:
I'm using beta2. I'm trying to create a gridview dynamically with a passed in SQL statement, everything works paging, sorting, and adding columns dynamically with the code. Because the hidden...
2
by: Narshe | last post by:
I have a gridview with datakeyname="Id" that is using a sqldatasource. When I click delete on the gridview, the datakeys property is empty during the deleting event.
1
by: | last post by:
I got stuck today on an annoying problem involving DataKeys, datasources, and the GridView: I kept getting errors saying things to the effect of""Item has already been added. Key in dictionary:...
6
by: Greg | last post by:
Hello, I have a GridView bound to a custom object. I set the DataKeyNames property along with the column DataField properties at design time, and bind the GridView to my object at run-time. In...
1
by: Rick Droske | last post by:
In the PageIndexChanged event of an ASP.Net 2.0 GridView the Rows property has rows but the DataKeys property has 0 Items ? This definitely seems like a bug to me. Has anyone come up with a good...
0
by: Benton | last post by:
Hi there, I have a GridView with DataKeyNames="SID" on the markup. To me surprise, I can get this value just fine in the RowDeleting and RowEditing events, for instance: string pk =...
1
by: teju | last post by:
Hello, I have two datakeys defined in the grid view. I want to access the both the datakeys when u click a button. Iam able to access one of the datakeys but not the other. Below is the code ...
0
by: VB Programmer | last post by:
From the research I've done, when you are using a gridview and want to programatically refer to a column that is hidden you have to add it to the datakey of the gridview. I've done that for 2 of...
0
by: =?Utf-8?B?cmxt?= | last post by:
I have a gridview updating every 5 seconds. There are several DataKeys declared which I access successfully in the RowDataBound event. However, in the ROwCommand event the count of the DataKeys...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.