.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

error in grid view reg

Posted By: Gowthammanju     Posted Date: June 02, 2011    Points:5   Category :ASP.Net
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

Responses
Author: sri             
Posted Date: June 02, 2011     Points: 20   

Dim Row As GridViewRow = gridname.Rows(gvemp.SedIndex)
Dim strgrid1stvalue,2ndcolumnvalue,3rdcolvalue As String
strgrid1stvalue = Row.Cells(1).Text /// to select the selected row's first cell value
2ndcolumnvalue= Row.Cells(2).Text
3rdcolvalue = Row.Cells(3).Text
now write the delete qry with where condition with above values

Author: Gowthammanju             
Posted Date: June 03, 2011     Points: 20   

Ya, Thanks sri

i too got the solution as,

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,
}



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


Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend