将CheckedChanged事件复选框添加到动态GridView

我想动态地向动态GridView添加一个复选框和一个Event。

即对于网格,我必须根据数据库添加动态选中或取消选中的复选框。 通过单击复选框本身,我想更新数据库。

为此,我需要将事件与复选框一起动态加载。

我完成的是一个静态版本,在这里展出:

在数据库RoleID(管理员,采购官等)中,存储ActivityID(离开应用程序等)和OperationID(保存,编辑等)。

对于Admin(roleid 1),第一行表示允许活动离开应用程序(Activityid 3)的保存操作(OperationID 1)。

如果要在运行时添加复选框,则在添加复选框时,需要定义复选框事件。

例如 :

TableCell tcCheckCell = new TableCell(); var checkBox = new CheckBox(); checkBox.CheckedChanged += checkBox_CheckedChanged; tcCheckCell.Controls.Add(checkBox); gridView.Rows[0].Cells.AddAt(0, tcCheckCell); void checkBox_CheckedChanged(object sender, EventArgs e) { //do something: You can use Krishna Thota's Code. } 

对不起,请关注此事

在gridview中放置一个复选框

这是一个示例HTML代码,用于在gridview中声明一个复选框

       

现在关于复选框的事件

 protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { GridViewRow row = ((GridViewRow)((CheckBox)sender).NamingContainer); int index = row.RowIndex; CheckBox cb1 = (CheckBox)Gridview.Rows[index].FindControl("CheckBox1"); string checkboxstatus; if (cb1.Checked == true) checkboxstatus = "YES"; else if(cb1.Checked == false) checkboxstatus = "NO"; //Here Write the code to connect to your database and update the status by //sending the checkboxstatus as variable and update in the database. }