我有带有连接DetailsView的SqlDataSource,我想取消更新行,当我的条件在OnRowUpdating事件中为真时,我执行了这一步骤,但是当条件为true时,DetailsView仍然处于编辑模式,如果条件为true,则需要返回到正常视图。
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);
}发布于 2015-10-05 11:45:10
在ChangeMode上使用DetailsView方法
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);https://stackoverflow.com/questions/32947570
复制相似问题