Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,

I use following code to retrive the values from grid view to label


ds = autosql.ShowDatas("SELECT * FROM Fax_Tablename");
            if (ds.Tables[0].Rows.Count > 0)
            {
                lbl_id.Text = ds.Tables[0].Rows[0]["cmid"].ToString();

            }



den i selected the GridView1_RowDeleting command in grid view to delete the selected row
as query

delete from Fax_tablename where cid='" + lbl_id.Text + "' "


if i select the delete button in grid view it deletes the first value in database since i am using

ds.Tables[0].Rows.Count



but my problem is

i need to delete the selected row in grid view on clicking the delete button



waiting for ur responces
thanks in advance


regards,
gowtham
Posted
Updated 2-Jun-11 0:39am
v2

1 solution

Ya, i got the solution as

<pre>protected void GridView1_DeleteCommand(object source, DataGridCommandEventArgs e)
{
int indx = e.Item.ItemIndex;
lbl_id.Text = GridView1.Items[indx].Cells[1].Text; //Change the cell name based on the primary key of the table,
}</pre>



<pre>delete from Fax_tablename where cid='" + lbl_id.Text + "' "</pre>



regards,
gowtham
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900