To implement the validation function in the DataGrid
The initial idea was to add a checkbox to the front of each line that triggers an event (such as: On Click= "Chk_click ()"), gets the ID of the current row and the Checked property value of the checkbox, and then updates the database when the checkbox is clicked.
Before I solved the problem, I searched through a lot of relevant documents, mostly how to implement the full selection, but also through a button to trigger the event, obviously do not meet their requirements, but still provide some information.
In fact, several problems are encountered:
The input parameter type of Chk_click () is object and System.EventArgs, how to get the ID and checked property values of the current row
Their level is poor, input parameters seemingly have no effect, I use the loop foreach (DataGridItem di in this. DATAGRID1.ITEMS) determine which line of the checkbox is clicked, and if it is a confirmed row, set the checkbox's Enable property to False when the data is bound so that when the first enable is true, The line that checked is true is the clicked line, then exits the loop, so the efficiency will be high. But again, in the event that the user is late for the wrong line, enable becomes false and cannot be modified, so the Enable property cannot be set. Finally, I use the checkbox's Checked property and the Flag field together to determine if the checked for True,flag 0 is a click confirmation line, and if checked is false,flag for 1 it is clicked to cancel the confirmation line.
foreach (DataGridItem di in this.) Datagrid1.items)
{
if ((CheckBox) di. FindControl ("Chk")). Checked = = True && ((Label) di. FindControl ("flag")). Text = = "0")
{
strSQL = "UPDATE table1 set flag = 1 WHERE id =" + di. CELLS[1]. Text;
Break
}
if ((CheckBox) di. FindControl ("Chk")). Checked = = False && ((Label) di. FindControl ("flag")). Text = = "1")
{
strSQL = "UPDATE table1 set flag = 0 WHERE id =" + di. CELLS[1]. Text;
Break
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.