且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ASP.NET中使用LINQ to SQL更新和删除Gridview行

更新时间:2023-02-06 23:13:54

hi
更新:
--------------
保留SNO的标签控件的ID为..."lblSno"
因此,从...更改代码.
hi
Update:
--------------
ID of label control that holds SNO is... "lblSno"
So change the code from...
int Sno = Convert.ToInt32((GridView1.Rows[e.RowIndex].FindControl("SNO") as Label).Text);






to

int Sno = Convert.ToInt32((GridView1.Rows[e.RowIndex].FindControl("lblSno") as Label).Text);



更好的代码将是..



better code will be..

int Sno = 0 ;
Label lblSno = GridView1.Rows[e.RowIndex].FindControl("lblSno") as Label
if (lblSno != null)
{
    int.TryParse(lblSno.Text, out Sno);
}



这样可以防止错误.

对于删除
---------------------

我认为您的单元格索引(即



This way you can prevent error.

For Delete
---------------------

I think your cell index (i.e

Cells[0]

)不正确. plesae检查以下行

希望对您有帮助

) is not right. plesae check the following line

Hope this will help you

string favoritesId = GridView1.Rows[e.RowIndex].Cells[0].Text;