我有一个要求,我想通过在每一行中放置复选框来删除多行我只想放置一个按钮来删除gridview中的多行......
我正在使用此代码,但它不起作用...
EmployeeModel.EmployeeEntities obj=new EmployeeModel.EmployeeEntities();
foreach(GridViewRow row in grdVw.Rows)
{
if ((row.FindControl("chkBox1") as CheckBox).Checked)
{
string id=grdVw.DataKeys[row.RowIndex].Value.ToString();
int a=int.Parse(id);
var result = from n in obj.Emps where n.Ecode == a select n;
obj.DeleteObject(result.First());
}
}
obj.SaveChanges();
这是声明 my 的代码GridView
:
<asp:GridView ID="grdVw" runat="server" AutoGenerateColumns="false" ToolTip="Employee Details" DataKeyNames="Ecode">
<Columns>
<asp:TemplateField HeaderText="select">
<ItemTemplate>
<asp:CheckBox ID="chkBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="EmpCode" DataField="Ecode" />
<asp:BoundField HeaderText="EmpName" DataField="Ename" />
<asp:BoundField HeaderText="Address" DataField="Address" />
<asp:BoundField HeaderText="City" DataField="city" />
<asp:BoundField HeaderText="EmailId" DataField="Email" />
<asp:BoundField HeaderText="DOB" DataField="DOB" />
<asp:BoundField HeaderText="JoinDate" DataField="joinDate" />
<asp:BoundField HeaderText="Salary" DataField="Salary" />
</Columns>
</asp:GridView>