我DetailsView
已连接SqlDataSource
我希望在OnRowUpdating
事件中我的条件为真时取消更新行
我做了这一步但当条件为真时DetailsView
仍处于编辑模式时,如果条件为真,我需要返回正常视图
protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
// Iterates through the rows of the GridView control
foreach (DetailsViewRow row in DetailsView1.Rows)
{
// Selects the text from the TextBox
// which is inside the GridView control
// Selects the text from the DropDownList
// which is inside the GridView control
string dropDownListText = ((DropDownList)
row.FindControl("DropDownList12")).SelectedItem.Text;
SqlConnection conn = new SqlConnection(GetConnectionString());
SqlCommand cmd2 = new SqlCommand();
conn.Open();
cmd2.CommandText = @"Select StatusID from ComplainMain Where TicketID=@tktid";
cmd2.Parameters.AddWithValue("@tktid", ticketid.tktid);
cmd2.Connection = conn;
SqlDataReader rdr = cmd2.ExecuteReader();
int status;
while (rdr.Read())
{
status = rdr.GetInt32(0);
if (status == 3)
{
Label18.Visible = true;
Label18.Text = "Can not Modify this Complaint as Ticket Closed refer to the Admin";
e.Cancel = true;
}
}
}
}
的Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Label18.Visible = false;
DetailsView1.ItemUpdating += new DetailsViewUpdateEventHandler(DetailsView1_ItemUpdating);
}